I have the following dataframe in R:
#dataframe
data <- cbind.data.frame(Line = 1:6,
Group = c(rep("A", 3), rep("B", 3)),
Value = c(1, 2, 4, 1, 2, 3))
So the table looks like this:
Line Group Value
1 A 1
2 A 2
3 A 4
4 B 1
5 B 2
6 B 3
Now I want to calculate for each group, the difference to the first value in the group (which is a control value), so:
Line 1 - Line 1
Line 1 - Line 2
Line 1 - Line 3
Line 4 - Line 4
Line 4 - Line 5
Line 4 - Line 6
I think this should work in a loop but I wanted to ask if there is maybe an easier way to that calculation? Thank you very much!