Skip to content
Prev 275151 / 398506 Next

Calculating difference between values in data frame based on separate column

Here's another way, using the reshape2 package:

library(reshape2)
d <- dcast(df, vial ~ measure, value_var = 'value')
d$diff <- with(d, B - A)
vial  A  B diff
1    1 12 26   14
2    2 30 45   15
3    3 27 32    5
4    4  6 34   28

HTH,
Dennis
On Fri, Oct 21, 2011 at 3:31 PM, Nathan Miller <natemiller77 at gmail.com> wrote: