I am trying to combine multiple columns into a vector (ideally I would like to specify which columns using some regex or dplyr::contains(). Anyways, I am NOT looking to concatenate columns or a solution using paste (I want to be able to use an %in% statement on the resulting vector. I want the new column to be a vector of values, which could be unnested using unnest_wider or some similar function. I am sure this is possible, just can't think of the right search terms for now. This seems to be close, but does not work:
df <- tribble(~A, ~B,
1, 2,
3, 4,
5, 6)
df %>%
mutate(C = I(list(A, B)))
The result would look something like this
A B C
1 1 2 c(1,2)
2 3 4 c(3,4)
3 5 6 c(5,6)