Entering edit mode
9.0 years ago
writersblog02
▴
70
I have a table:
W X Y Z
A 2 3 4
A 2 3 6
B 1 2 3
C 3 2 1
B 1 3 4
B 1 2 2
# reproducible data
table <- read.table(textConnection("W\tX\tY\tZ
A\t2\t3\t4
A\t2\t3\t6
B\t1\t2\t3
C\t3\t2\t1
B\t1\t3\t4
B\t1\t2\t2"), header = TRUE)
I want to combine all rows with same value in Column W, so that it looks like
W X Y Z
A 2 3 2,6
B 1 2,3 3,4,2
C 3 2 1
Note: All different values of column W entries appear as comma separated.