I\'m trying to use one column to determine which column to use as the value for another column It looks something like this:
X Y Z Target 1 a b
library(tidyverse) df <-setNames(data.frame(cbind(matrix(letters[1:9],3,3,byrow=T), c("X", "Y", "Z"))), c("X", "Y", "Z", "Target")) df df %>% gather(key="ID", value="TargetValue", X:Z) %>% filter(ID==Target) %>% select(Target, TargetValue) %>% left_join(df, by="Target")