Let’s say I have the following:
<code>df=read.table(text="ID ColB ColC ColD
1 A S1 X,Y,Z
2 A S2 A,B,C
3 B S3 A,B,C
4 B S4 X
5 C S6 X
6 C S8 X
", header=TRUE)
</code>
<code>df=read.table(text="ID ColB ColC ColD
1 A S1 X,Y,Z
2 A S2 A,B,C
3 B S3 A,B,C
4 B S4 X
5 C S6 X
6 C S8 X
", header=TRUE)
</code>
df=read.table(text="ID ColB ColC ColD
1 A S1 X,Y,Z
2 A S2 A,B,C
3 B S3 A,B,C
4 B S4 X
5 C S6 X
6 C S8 X
", header=TRUE)
I want to merge duplicated rows based on ColB while merging ColC and ColD on these rows, such as the results are:
<code>df=read.table(text="ID ColB ColC ColD
1 A S1,S2 X,Y,Z,A,B,C
2 B S3,S4 A,B,C,X
3 C S6,S8 X
", header=TRUE)
</code>
<code>df=read.table(text="ID ColB ColC ColD
1 A S1,S2 X,Y,Z,A,B,C
2 B S3,S4 A,B,C,X
3 C S6,S8 X
", header=TRUE)
</code>
df=read.table(text="ID ColB ColC ColD
1 A S1,S2 X,Y,Z,A,B,C
2 B S3,S4 A,B,C,X
3 C S6,S8 X
", header=TRUE)
As you can see, because ColD, row 5 a 6 had the same value, the resulting ColD row 3 contains only the X value.
I’m not sure where to start in this case and any help is appreciated!