I am trying to summerise a grouped dataset with summerise_each
. Somehow it is not possible to drop the grouping variable before summarising (I tried it with dplyr::select
). The problem is that the grouping variable is not numeric and I want the sum all columns.
library(dplyr)
group <- sample(c("a","b","c"), 100, replace = TRUE,)
values <- matrix(rnorm(1000), ncol = 10)
data <- data.frame(group, values)
data %>% group_by(group) %>% summarise_each(sum)
Error in UseMethod("as.lazy_dots") : no applicable method for 'as.lazy_dots' applied to an object of class "function"
I want this output but for all columns.
data %>% group_by(group) %>% summarise(sum(X1))´
group sum(X1)
(fctr) (dbl)
1 a 2.648381
2 b 5.532697
3 c 1.382693
I do not want to use summarise(sum(X2), sum(X2), ...)