Skip to content
Prev 236073 / 398500 Next

subtraction based on two groups in a dataframe

Try something like this:



dfr <- 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 "))


difs <- lapply(split(dfr,dfr$plate.id), function(x)x$rlt1[x$Group ==
"Control"] - x$rlt1[x$Group == "ovca"])
dfr$Diff <- Reduce(c,difs)



greetings,
Remko