0

两个数据集:

people <- read.table(text="
pid
1
2
3
4
", header=TRUE)

comps <- read.table(text="
pid comp rank
1   1    0
1   3    1
1   2    2
2   4    0
2   1    1
2   3    2
3   1    0
3   2    1
3   4    2
", header=TRUE)

尝试获取每个唯一的数据框pid及其比较列表,例如:

pid comps
1   1,3,2
2   4,1,3
3   1,2,4

来不及了。。

4

1 回答 1

0

你可以这样做aggregate

aggregate(comp~pid, comps, paste, collapse=",")
#   pid  comp
# 1   1 1,3,2
# 2   2 4,1,3
# 3   3 1,2,4
于 2015-05-21T23:59:21.493 回答