You can either use group_by or group_by_at
Using group_by
# Generate data
set.seed(492)
data = data.frame(value=rnorm(1000), z1=sample(LETTERS,1000,replace=TRUE), z2=sample(letters,1000,replace=TRUE), z3=sample(1:10, replace=TRUE), colour=sample(c("red","green","black"),1000,replace=TRUE))
data %>% group_by_(.dots=names(data)[-grep("value", names(data))]) %>%
summarise(mean_value=mean(value)
#Output
z1 z2 z3 colour mean_value
<fctr> <fctr> <int> <fctr> <dbl>
1 A a 2 green 0.89281475
2 A b 2 red -0.03558775
3 A b 5 black -1.79184218
4 A c 10 black 0.17518610
5 A e 5 black 0.25830392
...
You can also use group_by_at in the following way:
data %>%
group_by_at(names(data)[-grep("value", names(data))]) %>%
summarise(mean_value=mean(value))
# Groups: z1, z2, z3 [?]
z1 z2 z3 colour mean_value
<fctr> <fctr> <int> <fctr> <dbl>
1 A a 2 green 0.89281475
2 A b 2 red -0.03558775
3 A b 5 black -1.79184218
4 A c 10 black 0.17518610
5 A e 5 black 0.25830392
6 A e 5 red -0.81879788
7 A e 7 green 0.30836054
8 A f 2 green 0.05537047
9 A g 1 black 1.00156405
10 A g 10 black 1.26884303
# ... with 949 more rows