I have the following data frame data
ID A B C
X 1 1 1
X 0 1 0
Y 2 0 0
Z 0 0 0
And I want to use group_by and summarise (dplyr package) to create a new data frame with sum of all values of A and B and C, group by ID.
Output should be like below:
ID A B C
X 1 2 1
Y 2 0 0
Z 0 0 0
My code is below:
data_new <- data %>%
group_by(ID) %>%
summarise(Total.A = sum(A)) %>%
summarise(Total.B = sum(B))
However, the code only works with summing A and after that, I have an error says
Error in summarise_impl(.data, dots) : Evaluation error: object 'B' not found.
Could you please help out?