相关疑难解决方法(0)

R - 添加在组内按顺序计数但在重复时重复的列

我正在寻找一种解决方案来添加"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)

r dataframe dplyr

3
推荐指数
2
解决办法
943
查看次数

标签 统计

dataframe ×1

dplyr ×1

r ×1