the data
id total_years total_love_years total_years30 total_love_years30 first_match true_value true_love_value
1 18 282 373 1991 total_years 18 282
2
3
4
essentially I want to create the latter two columns "true_value" and "true_love_value" based on the column name in "first_match". in creating the "true_value" column, I look at the "first_match" column. it says "total_years",hence I am taking the value in "total_years". similarly, for "true_love_value" column I am taking the value in "total_love_years", as the first_match column is for "total_years" and not "total_years30". I think I know how to make the first column. making the second column is now the difficult part you seen.
my code is using the tidy verse and is follows:
data %>%
rowwise() %>%
mutate(true_value = cur_data()[[first_match]])
again, I want to make mutate create me a new column titled "true_love_value" that gives me the value in "total_love_years" column.. I select the value from "total_love_years", as the "first_match" column directs me to do so.
is there a way to do this with paste0 maybe. I have a several different columns I want to do this for, so i want to avoid a case_when. this data is a much more simplified version but illustrates the issue
thank u