This is a continuation of a past question I asked. Basically, I have a dataframe, df
Beginning1 Protein2 Protein3 Protein4 Biomarker1
Pathway3 A G NA NA F
Pathway6 A G NA NA E
Pathway2 A B H NA F
Pathway5 A B H NA E
Pathway1 A D K NA F
Pathway7 A B C D F
Pathway4 A B C D E
And now I want to consolidate the rows to look like this:
dfnew
Beginning1 Protein2 Protein3 Protein4 Biomarker1
Pathway3 A G NA NA F, E
Pathway2 A B H NA F, E
Pathway7 A D K NA F
Pathway1 A B C D F, E
I've seen a lot of people consolidate identical rows in dataframes using aggregate, but I can't seem to get that function to work on non-numerical values. The closest question I have seen solved it like this: df1 <- aggregate(df[7], df[-7], unique)
and can be found here: Combining duplicated rows in R and adding new column containing IDs of duplicates.
Also, not every pathway has a matching pair, as can be seen in pathway 1.
Thank you so much for your help!