I apologize if the articulation of my question is confusing, I haven't been able to find similar threads which clarify the English of my question.
I am working with a sample of data which resembles that seen below:
label1 | label2 | label3 | label# |
---|---|---|---|
value1 | value4 | value7 | label2 |
value2 | value5 | value8 | label1 |
value3 | value6 | value9 | label3 |
I'm trying to create a new column, 'currentvalue', which reads in the value of label# in a certain row, then for that row populates the column with that row's value of whatever column is named in label#. In other words, I want my output to look like this:
label1 | label2 | label3 | label# | currentvalue |
---|---|---|---|---|
value1 | value4 | value7 | label2 | value4 |
value2 | value5 | value8 | label1 | value2 |
value3 | value6 | value9 | label3 | value9 |
The only solutions I can think of for this involve multiple for loops, which I imagine is very computationally inefficient. I've been searching stack overflow for threads which could help me write a vectorized solution to this, but I don't think I've been able to articulate the problem very well because none of my searches were helpful. Any help is appreciated (including help stating my question better).