I have a dataset where I want to simply use an alias name for a column name and apply that to a dplyr group_by/summarise function.
Here is an example.
alias = 'cust'
alias2 = 'class'
df <- data_frame(cust = c("A", "B", "A", "C", "B"), class = c(1, 2, 3, 4, 7))
df
cust class
<chr> <dbl>
1 A 1
2 B 2
3 A 3
4 C 4
5 B 7
Here is the original dplyr function:
df %>%
dplyr::group_by(cust) %>%
dplyr::summarise(test = max(class) )
Result:
cust test
<chr> <dbl>
1 A 3
2 B 7
3 C 4
Here is my attempt with the alias name:
df %>%
dplyr::group_by(!!alias) %>%
dplyr::summarise(test = max(!!alias2) )
`"cust"` test
<chr> <chr>
1 cust class
How do I run this code with an alias? Any help would be great thanks!