This is best explained with an example. In the table below I want to create a new column (col4) where the value is equal to the value in the column name referenced in col3.
set.seed(1)
data <- tibble(
col1 = runif(10),
col2 = runif(10),
col3 = sample(c("col1", "col2"), 10, replace = TRUE)
)
So the desired result (manually created) would be as follows
data$col4 <- c(0.26550866, 0.37212390, 0.57285336, 0.90820779, 0.20168193, 0.89838968, 0.7176185, 0.66079779, 0.62911404, 0.7774452)