I have a set of data frame as below:
| ID | Parameter | value |
|---|---|---|
| 123-01 | a1 | x |
| 123-02 | a1 | x |
| 123-01 | b3 | x |
| 123-02 | b3 | x |
| 124-01 | a1 | x |
| 125-01 | a1 | x |
| 126-01 | a1 | x |
| 124-01 | b3 | x |
| 125-01 | b3 | x |
| 126-01 | b3 | x |
I would like to find the sampleID that ended with "-02", and calculate the difference of the same sample ID that has the same first three digit by same parameter.
For example, calculate the difference of 123-01 and 123-02 based on parameter a1. Then the difference of 123-01 and 123-02 based on parameter b3, etc....
In the end, I can get a table contains
| ID | Parameter | DiffValue |
|---|---|---|
| 123 | a1 | y |
| 123 | b3 | y |
| 127 | a1 | y |
| 127 | b3 | y |
How can I do it?
I tried to use dplyr (filter) to create a table that only contains the duplicate, and then how do I match the origin table and do the calculation?