I have a dataframe like the following
Sample ID | Parameter | Value | Unit |
---|---|---|---|
1 | apple | 30 | g |
1 | pear | 15 | lb |
1 | organge | 20 | kg |
2 | apple | 2 | g |
2 | pear | 3 | lb |
2 | orange | 10 | kg |
3 | apple | 15 | g |
3 | pear | 23 | lb |
3 | orange | 12 | kg |
I would like to transpose it based on the sample ID and put the corresponding value in the column
Sample ID | apple_value_unit(g) | pear_value_unit(lb) | orange_value_unit(kg) |
---|---|---|---|
1 | 30 | 15 | 20 |
2 | 2 | 3 | 10 |
3 | 15 | 23 | 12 |
Is there any ways that I can transpose and match the value? I tried the cast(), but it does not work on mapping the value to the corresponding parameter.