I have a long list of columns, and values from the score columns into one column. However, rather than typing them all out, I'd like to just use contains("test") within the paste function--is this possible?
Here's my data and what I want it to look like:
library(dplyr)
#What I have :(
test <- tibble(id = c(1:2),
test_score = c(4,5),
test_building = c("Lupton", "Hearst"),
initials = c("s", "j"))
#What I want ^_^
answer <- tibble(id = c(1:2),
test_score = c(4,5),
test_building = c("Lupton", "Hearst"),
initials = c("s", "j"),
test_combo = c("4, Lupton", "5, Hearst"))
And here's a graveyard of some failed attempts that I've tried:
test %>%
mutate(test_combo = paste(vars(contains("test"))))
test %>%
mutate(test_combo = paste(across(contains("test"))))
I'd like the order to be test_score and then test_building, but order really isn't that important, so I'd take a simple solution that pastes them correctly in the 'wrong' order versus a very complex path to put them in the 'right' order.