[R] subtraction based on two groups in a dataframe

1Rnwb sbpurohit at gmail.com
Mon Sep 27 21:47:43 CEST 2010


Hello 

I have a data set like below:
    plate.id well.id   Group      HYB  rlt1
1         P1      A1 Control SKOV3hyb 0.190
2         P1      A2 Control SKOV3hyb 0.210
3         P1      A3 Control SKOV3hyb 0.205
4         P1      A4 Control SKOV3hyb 0.206
5         P1      A5 Control SKOV3hyb 0.184
385       P1      A1    ovca SKOV3hyb 0.184
386       P1      A2    ovca SKOV3hyb 0.229
387       P1      A3    ovca SKOV3hyb 0.214
388       P1      A4    ovca SKOV3hyb 0.226
389       P1      A5    ovca SKOV3hyb 0.217
390       P1      A6    ovca SKOV3hyb 0.207


each plate.id contains 384 readings for Group=="Control" and the same
plate.id will contain 384 readings for Group=='ovca' to give a total of 768
values for P1 and so on for other plate ID's. I have to take the subtract
the values of rlt1 colum between the two groups based on Plate ID.

currently I am using
> newdat2$diff<-(newdat2[1:5,5]-newdat2[6:10,5])/newdat2[1:5,5]*100
> newdat2
    plate.id well.id   Group      HYB  rlt1       diff
1         P1      A1 Control SKOV3hyb 0.190   3.157895
2         P1      A2 Control SKOV3hyb 0.210  -9.047619
3         P1      A3 Control SKOV3hyb 0.205  -4.390244
4         P1      A4 Control SKOV3hyb 0.206  -9.708738
5         P1      A5 Control SKOV3hyb 0.184 -17.934783
385       P1      A1    ovca SKOV3hyb 0.184   3.157895
386       P1      A2    ovca SKOV3hyb 0.229  -9.047619
387       P1      A3    ovca SKOV3hyb 0.214  -4.390244
388       P1      A4    ovca SKOV3hyb 0.226  -9.708738
389       P1      A5    ovca SKOV3hyb 0.217 -17.934783

I have tried 
apply(newdat2, 1, function(x) tapply(x, plate.id,
newdat2$Control-newdat2$ovca)))

I am looking for a more simple way to calculate the percent difference
between the each value (based on well.id) for the two groups for 100's of
plate.ids.

I would appreciate help in getting this solved.
Thanks

-- 
View this message in context: http://r.789695.n4.nabble.com/subtraction-based-on-two-groups-in-a-dataframe-tp2716104p2716104.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list