I have a data frame like
> df[1:10,]
SID Group Source
1 1 10 C04
2 1 5 M04
3 1 5 M02
4 1 5 M03
5 2 40 M04
6 2 40 M02
7 2 40 M03
8 3 45 M01
9 3 40 M01
10 3 40 C01
Now I want to merge the Source-Column based on SID and Group. So that I get the following Output
SID Group Source
1 1 10 {C04}
2 1 5 {M04, M02, M03}
3 2 40 {M04, M02, M03}
4 3 45 {M01}
5 3 40 {M01, C01}
...
I already tried to use aggregate
> y <- as.data.frame(aggregate(Source~., data=df, paste,collapse=",", na.rm=TRUE))
and order the results based on
> y <- y[order(y$SID,-y$Group),]
which delivers almost the expected result
SID Group Source
1 1 10 C04 TRUE
2 1 5 M04 TRUE,M02 TRUE,M03 TRUE
3 2 40 M04 TRUE,M02 TRUE,M03 TRUE
4 3 45 M01 TRUE
However I want to get rid of the TRUEs in my last column and I would like to know why do I get these and how can I avoid them?
Does someone have a clue or maybe an explanation? I appreciate your help.