I'd like to select and return a column value contained within one of a subset of columns, based on the value in another column.
Specifically, I'd like to create a new variable ("NEWE") by selecting the value in RE when the MAX variable = "RP" and by selecting the value in IE when the MAX variable = "IP".
Of note, I am working with a data table of ~160 columns and ~70,000 rows (I am noting the existence of additional columns in my example by including V1-V9).
Have:
V1 … V9 RE IE MAX
4 … 3 3 4 RP
6 … 6 3 2 IP
2 … 2 1 2 IP
6 … 2 2 3 RP
. . . . . .
. . . . . .
. . . . . .
And the data set I would like:
V1 … V9 RE IE MAX NEWE
4 … 3 3 4 RP 3
6 … 6 3 2 IP 2
2 … 2 1 2 IP 2
6 … 2 2 3 RP 2
. . . . . . .
. . . . . . .
. . . . . . .
Thanks in advance for your help!
ifelse?