I have a dataset as follow :
A <- rnorm(5)
B <- rnorm(5)
C <- rnorm(5)
D <-c(1,3,2,2,1)
data_ex <-data.frame(A,B,C,D)
And I would like to get the name of the column corresponding to the value of the column D. The goal is then to create a new column (E) with the values corresponding.
If data_ex$D[1]=1 then data_ex$E will take the value of column A, as it is the 1 st one
Does anyone have an idea on how to do it?
Thanks!