Skip to content
Prev 305767 / 398506 Next

help with calculation from dataframe with multiple entries per sample

The following works even when the input data frame has its rows
scrambled.  It does not currently check that there is exactly one entry
in each sample for Time==2 and Time==3.

within(mydata, 
            `Gain2-3` <- ave(seq_along(Sample),
                                          Sample,
                                          FUN=function(i) {
                                             L2 <- Time[i]==2
                                             L3 <- Time[i]==3
                                             Mass[i][L3] - Mass[i][L2] }))

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com