I’d like to combine multiple columns of a data frame in R. Given data that look something like this:
names: 123 256 192 123 256
1 2 8 2 3
4 3 2 9 9
8 7 1 3 8
How would I sum the elements of the identically-named columns to produce a table like so:
names: 123 256 192
3 5 8
13 12 2
11 15 1
Thank you very much.
As suggested by @VincentZoonekynd it is not a good idea to have multiple columns with the same name.
Anyway, you could do in this way:
or, in one line: