My data are in a dataframe like this:
id | A | B | C | D | E | F | G | H | Cl |
---|---|---|---|---|---|---|---|---|---|
P_1 | 23 | 25 | 27 | 30 | 31 | 33 | 35 | 37 | 5 |
P_2 | 20 | 27 | 25 | 30 | 28 | 32 | 26 | 26 | 3 |
P_3 | 17 | 24 | 25 | 32 | 25 | 31 | 26 | 32 | 2 |
P_4 | 14 | 24 | 25 | 33 | 22 | 30 | 22 | 38 | 6 |
P_5 | 11 | 24 | 25 | 35 | 19 | 29 | 23 | 44 | 5 |
P_6 | 8 | 24 | 25 | 30 | 16 | 28 | 20 | 50 | 6 |
- | - | - | - | - | - | - | - | - | - |
- | - | - | - | - | - | - | - | - | - |
- | - | - | - | - | - | - | - | - | - |
P_10008 | - | - | - | - | - | - | - | - | - |
I have a dataframe with more than 10,000 rows and 14 columns (example attached in text using 8 columns). I indexed the row and column number from which I need to extract the value. The "Cl" column includes the column number (also id column) from which I would like to extract that value for each row. For example, from the first row I would like to extract the value “30” from the “D” column and also would like to keep the id column (P_1). Column “B” from the 2nd row with id P_2.
New dataset would be like,
id | value |
---|---|
P_1 | 30 |
P_2 | 27 |
P_3 | 17 |
P_4 | 22 |
P_5 | 35 |
P_6 | 16 |
- | - |
- | - |
P_10008 | - |
How do I write the code in a way in R that would allow me to extract the value of a cell with the row and column number for my whole dataset? Any help would be appreciated.