You can use the group_by_at function from the dplyr package to group by multiple columns using string vector inputs.
The basic syntax is as follows:
group_by_at(.tbl, .vars, .funs = list(), ..., .add = FALSE,
.drop = group_by_drop_default(.tbl))
Where
.tbl
A tbl object.
.funs
A function fun, a quosure style lambda ~ fun(.) or a list of either form.
...
Additional arguments for the function calls in .funs. These are evaluated only once, with tidy dots support.
.drop
When .drop = TRUE, empty groups are dropped.
.vars
A list of columns generated by vars(), a character vector of column names, a numeric vector of column positions, or NULL.
one_of(): Variables in character vector
In your case:
data = data.frame(
asihckhdoydkhxiydfgfTgdsx = sample(LETTERS[1:3], 100, replace=TRUE),
a30mvxigxkghc5cdsvxvyv0ja = sample(LETTERS[1:3], 100, replace=TRUE),
value = rnorm(100)
)
columns = names(data)[-3]
data %>%
group_by_at(vars(one_of(columns))) %>%
summarize(MeanValue = mean(value))
Output:
# A tibble: 9 x 3
# Groups: asihckhdoydkhxiydfgfTgdsx [3]
asihckhdoydkhxiydfgfTgdsx a30mvxigxkghc5cdsvxvyv0ja MeanValue
<fct> <fct> <dbl>
1 A A 0.588
2 A B 0.113
3 A C 0.178
4 B A -0.397
5 B B -0.118
6 B C -0.461
7 C A 0.117
8 C B -0.583
9 C C -0.382