I have the following example data frame:
model <- c(1,1,1,1,2,2,3,3,3)
variable <- letters[seq(1:9)]
df <- data.frame(model , variable)
model variable
1 1 a
2 1 b
3 1 c
4 1 d
5 2 e
6 2 f
7 3 g
8 3 h
9 3 i
and I would like to "collapse" the field variable grouped by model. If variable were numeric it would be a sum, or some other operator. However, this being character, I would like to paste the values.
model variable
1 1 a b c d
2 2 e f
3 3 g h i