Say I have a list called df such that colnames(df)
yields:
"A" "B" "C" "D" "E" "F"
I would like aggregate data in the following way:
aggregate(cbind(`C`,`D`,`E`,`F`)~A+B, data = df, FUN = sum)
Of course I could do it "manually" but in my true data I have a very big amount of columns, so I am trying to change the colnames(df)[3:6]
output to yield:
`C`,`D`,`E`,`F`
instead. So far I have tried to use toString(colnames(df)[3:6])
which yields:
"C, D, E, F"
But this is not read properly by cbind
.
Any suggestions?