I am trying to find a way to summarise multiple columns column-wise in R by specifying the column that I don't want to summarise. For example in the following case I want do summarise all columns that are not named "cat" or "type":
This data frame:
df <- data_frame(cat = c('A', 'B', 'C'),
val1 = c(0.1, 0.3, 0.5),
val2 = c(0.2, 0.2, 0.7),
val3 = c(0.14, 0.31, 0.35),
type = c(4, 2, 5))
To this one:
df <- data_frame(cat = c('A', 'B', 'C'),
val1 = c(0.1, 0.3, 0.5),
val2 = c(0.2, 0.2, 0.7),
val3 = c(0.14, 0.31, 0.35),
type = c(4, 2, 5),
sum = c(0.44,0.81,1.55))
I have been trying using dplyr mutate functions to do this but I cannot figure out how to do it.
Any suggestion of how to do this would be super appreciated.