I have a dataframe like this:
id reason x1 x2 x3 x4 x5
1 x1 100 15 10 20 25
2 x1 15 16 14 10 10
3 x4 10 50 40 30 25
4 x3 12 15 60 5 1
5 x1 80 15 10 20 25
6 x1 15 19 84 10 10
7 x4 90 40 90 30 25
8 x4 12 85 60 50 10
The xy column must be filled with the value of the column names in the reason column. Let's look at the first row. The reason column shows our value x1. So our value in column xy, will be the value of x1 column in the first row. Like this:
id reason x1 x2 x3 x4 x5 xy
1 x1 100 15 10 20 25 100
2 x1 15 16 14 10 10 15
3 x4 10 50 40 30 25 30
4 x3 12 15 60 5 1 60
5 x1 80 15 10 20 25 80
6 x1 15 19 84 10 10 15
7 x4 90 40 90 30 25 30
8 x4 12 85 60 50 10 50
Is there a way to do this?