I have the problem to merge certain characters of a group into a new column, e.g.
df = read.table(text="ID Class
1 a
1 b
2 a
2 c
3 b
4 a
4 b
4 c", header=T)`
and the output should be something like
ID Class Class.aggr
1 a a, b
1 b
2 a a, c
2 c
3 b b
4 a a,b,c
4 b
4 c`
I thought about using cat(union)
, but the data sample size is very high and I don't know how to call the Class characters dependent on the ID (tapply doesn't seem to work).