Hi:

Perhaps this might be useful:

tst <- read.table(textConnection("
+    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"), header = TRUE)

tst2 <- reshape(tst, idvar = c('plate.id', 'well.id'), timevar = 'Group',
                 direction = 'wide')
tst2
  plate.id well.id HYB.Control rlt1.Control HYB.ovca rlt1.ovca
1       P1      A1    SKOV3hyb        0.190 SKOV3hyb     0.184
2       P1      A2    SKOV3hyb        0.210 SKOV3hyb     0.229
3       P1      A3    SKOV3hyb        0.205 SKOV3hyb     0.214
4       P1      A4    SKOV3hyb        0.206 SKOV3hyb     0.226
5       P1      A5    SKOV3hyb        0.184 SKOV3hyb     0.217

tst2$rlt1.diff <- rlt1.ovca - rlt1.Control

reshape() is reshaping the data based on plate.id * well.id combinations, so
the observations in Control and ovca should match on those two keys..

HTH,
Dennis


On Mon, Sep 27, 2010 at 12:47 PM, 1Rnwb <sbpuro...@gmail.com> wrote:

>
> 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.
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to