I am struggling to find an R function that will convert my data into “fold changes from baseline values”. Basically I have a data.frame consisting of subject.id and timepoints grouped by treatments with multiple species values as follows:
| subject.id | timepoint | treatment | Species1 | Species2 | Species3 | SpeciesX |
id1 baseline A 40 10 5 5
id1 2h A 41 12 5 6
id1 4h A 40 20 6 5
id2 baseline B 50 10 5 5
id2 2h B 100 20 5 6
id2 4h B 200 20 6 5
I need something like this keeping the same species names but with fold changes:
| subject.id | timepoint | treatment | Species1 | Species2 | Species3 | SpeciesX |
id1 baseline A 1 1 1 1
id1 2h A 1.02 1.2 1 1.2
id1 4h A 1 2 1.2 1
id2 baseline B 1 1 1 1
id2 2h B 2 2 1 1.2
id2 4h B 4 2 1.2 1
Any help would be very much appreciated!
Many thanks!
pepe84 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.