Re: [R] Calculating difference between values in data frame based on separate column

2011-10-21 Thread Dennis Murphy
Here's another way, using the reshape2 package: library(reshape2) d <- dcast(df, vial ~ measure, value_var = 'value') d$diff <- with(d, B - A) > d vial A B diff 11 12 26 14 22 30 45 15 33 27 325 44 6 34 28 HTH, Dennis On Fri, Oct 21, 2011 at 3:31 PM, Nathan Miller

Re: [R] Calculating difference between values in data frame based on separate column

2011-10-21 Thread Sarah Goslee
Hi, It shouldn't be so complicated. What about simply: > td vial measure value 21 A12 11 B26 42 A30 32 B45 63 A27 53 B32 84 A 6 74 B34 > td <- td[order(td$vial, td$measure),] # make s

[R] Calculating difference between values in data frame based on separate column

2011-10-21 Thread Nathan Miller
Hi all, Say I have a data frame something like the one below with different sample vials, measured before(B) and after(A) some process, with a value recorded at each measurement point vialmeasurevalue 1 B26 1 A12 2 B 45 2