我有以下数据框。
df <- data.frame(Person = c("Eric","Eric","Eric","Joe","Joe","Joe"), Order = c(2,7,4,2,5,1),
Value = c("A","A","B","C","A","B"))
Run Code Online (Sandbox Code Playgroud)
订单列当前处于随机顺序。每个人都有 3 个订单值,它们是 1 到 8 之间的随机整数。订单始终是 1 到 8 之间的值,并且没有重复。如何转换 Order 列,使其反映按人分组的值的顺序?因此,订单列将始终介于 1 和 3 之间。所需的输出将如下所示。
df <- data.frame(Person = c("Eric","Eric","Eric","Joe","Joe","Joe"), Order = c(1,3,2,2,3,1),
Value = c("A","A",'B","C","A","B"))```
Run Code Online (Sandbox Code Playgroud)