我正在寻找一种解决方案来添加"desired_result"列,最好使用dplyr和/或ave().请参阅此处的数据框,其中组是"section",我希望我的"desired_results"列按顺序计数的唯一实例位于"exhibit"中:
structure(list(section = c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), exhibit = structure(c(1L,
2L, 3L, 3L, 1L, 2L, 2L, 3L), .Label = c("a", "b", "c"), class = "factor"),
desired_result = c(1L, 2L, 3L, 3L, 1L, 2L, 2L, 3L)), .Names = c("section",
"exhibit", "desired_result"), class = "data.frame", row.names = c(NA,
-8L))
Run Code Online (Sandbox Code Playgroud)