Given we have 10 of each group, add an index 1:10, 1:10 and summarize over that with difference:
> datf2$entry=c(1:10,1:10)
> datf2 %.% ungroup() %.% group_by(entry) %.% summarize(d=cent[1]-cent[2])
Source: local data frame [10 x 2]
entry d
1 1 -0.8272879
2 2 -0.9159827
3 3 -0.5064762
4 4 0.4211639
5 5 1.3681720
6 6 3.3430289
7 7 1.0086822
8 8 -0.6163907
9 9 -0.7325220
10 10 -2.5423875
compare:
> gA - gB
cent
1 -0.8272879
2 -0.9159827
3 -0.5064762
4 0.4211639
5 1.3681720
6 3.3430289
7 1.0086822
8 -0.6163907
9 -0.7325220
10 -2.5423875
Is there a way to inject the entry
field into the data or the dplyr
call? I'm not sure, it seems to rely on the functions knowing too much about the data...