0

Two data sets:

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)

Trying to get a data frame of each unique pid with a list of their comparisons, like:

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

Can't quite get there..

josliber
  • 43,000
  • 12
  • 95
  • 132
Wells
  • 9,693
  • 10
  • 50
  • 77

1 Answers1

0

You can do this with aggregate:

aggregate(comp~pid, comps, paste, collapse=",")
#   pid  comp
# 1   1 1,3,2
# 2   2 4,1,3
# 3   3 1,2,4
josliber
  • 43,000
  • 12
  • 95
  • 132