Hi suppose I have a table with many columns ( in the thousands) and some rows that are duplicates. What I like to do is sum any duplicates for each row and for every columns. I'm stuck because I don't want to have to hard code or loop through each column and remerge. Is there a better way to do this? Here is an example with only 3 columns for simplicity.
dat <- read.table(text='name etc4 etc1 etc2
A 9 0 3
A 10 10 4
A 11 9 4
B 2 7 5
C 40 6 0
C 50 6 1',header=TRUE)
# I could aggregate one column at a time
# but is there a way to do for each columns without prior hard coding?
aggregate( etc4 ~ name, data = dat, sum)