Got a df:
ID Val1 Val2 Val3
A 1 1 1
A 1 1 1
A 1 1 1
B 0 0 1
I want to take the sum of all the columns, based on a unique ID value. Like this:
ID Val1 Val2 Val3
A 3 3 3
B 0 0 1
I tried:
df %>% group_by(ID) %>% summarise_all(funs(sum()))
Anyone have an advice about what I' m doing wrong? I prefer a dplyr approach (if possible).
dat %>% group_by(ID) %>% summarise_all(sum)?countandcount()will work as part of a dplyr chain). But in certain cases, the presence of parenthesis makes the difference between "call the function" versus "pass the function as an argument", as explained in the answer below.aggregate(. ~ ID, df, sum)does it. Find simpler.