I am working with a dataset that contains many columns that are similarly named (ex thing_1 , thing_2, blargh_1, blargh_2, fizz_1, fizz_2), and I've been trying to write a function that takes in a string (such as fizz) and performs some operation on all superstrings of the column (such as fizz_1 + fizz_2).
So far, I have structured my code into something that looks something like:
newData <- data %>%
mutate(fizz = f("fizz"))
f <- function(name) {
name_1 + name_2
}
where f as written obviously doesn't work. I've toyed around with assign, but not been terribly successful. I'm also open to other ways to tackle the problem (maybe a function that takes in a dataset and the string). Thanks!