I am attempting to reference a column in my data frame with paste given a variable name and the column is not being recognized. Below is an example data frame and variable names that I am attempting to work with:
arm <- "ARM"
ex_df <- data.frame(col1 = c("A","B","C"), col2 = c("X","Y","Z"), ARM_1 = c(1,2,3), ARM_2 = c(4,5,6,), ARM_3 = c(7,8,9), ARM_4 = c(0,0,0))
ex_df %>%
transmute(col1 = col1, col2 = str_to_title(col2), paste0(arm,"_",4) = paste0(arm,"_",1) + paste0(arm,"_",2) + paste0(arm,"_",3)) %>%
arrange(col1,col2)
Error: unexpected '=' in:
"col2 = str_to_title(col2),
paste0(arm,"_",4) = "
The desired output should read ARM_4 = ARM_1 + ARM_2 + ARM_3 and output the sum of each columns values.
Thank you for your help.