Here is my data:
df <- tibble::tribble(
~A, ~B, ~C,
"a", "b", 2L,
"a", "b", 4L,
"c", "d", 3L,
"c", "d", 5L
)
var <- "AB"
I want to get this output:
df1 <- df %>%
unite("AB", c("A", "B")) %>%
group_by(AB) %>%
nest()
However, I want to refer var, maybe using rlang. I do not want to manually input "AB". I tried the following, but not getting the desired output.
df1 <- df %>%
unite(var, c("A", "B")) %>%
group_by(!!var) %>%
nest()