Re: [R] subtraction based on two groups in a dataframe

2010-10-20 Thread 1Rnwb

I want the reshaped data to look like this.

  plate.id   HYBwell.id   rlt1.control1
well.id   rlt1.control1   well.idrlt1.disease1   well.id
rlt1.disease2
1   P1   SKOV3hyb   A10.190
A2 0.210 B10.217B2
0.190
2P1 SKOV3hyb   A3 0.205
A4 0.206 B30.371B4
0.56


Thanks
Sharad

On Thu, Oct 7, 2010 at 7:09 PM, djmuseR [via R] <
ml-node+2967676-1432920781-6...@n4.nabble.com
> wrote:

> Hi:
>
> Is this what you were looking for?
>
> plate.id well.id Group   HYB rlt1
> P1  A1  control1SKOV3hyb0.19
> P1  A2  disease1SKOV3hyb0.21
> P1  A3  control1SKOV3hyb0.205
> P1  A4  disease1SKOV3hyb0.206
> P1  B1  disease2SKOV3hyb0.217
> P1  B2  control2SKOV3hyb0.646
> P1  B3  disease2SKOV3hyb0.371
> P1  B4  control2SKOV3hyb
>
> dfwide <- reshape(df, idvar = c('plate.id', 'well.id', 'HYB'), timevar =
> 'Group',
>   direction = 'wide')
> > dfwide
>   plate.id well.id  HYB rlt1.control1 rlt1.disease1 rlt1.disease2
> 1   P1  A1 SKOV3hyb 0.190NANA
> 2   P1  A2 SKOV3hybNA 0.210NA
> 3   P1  A3 SKOV3hyb 0.205NANA
> 4   P1  A4 SKOV3hybNA 0.206NA
> 5   P1  B1 SKOV3hybNANA 0.217
> 6   P1  B2 SKOV3hybNANANA
> 7   P1  B3 SKOV3hybNANA 0.371
> 8   P1  B4 SKOV3hybNANANA
>   rlt1.control2
> 1NA
> 2NA
> 3NA
> 4NA
> 5NA
> 6 0.646
> 7NA
> 8 0.560
>
>
> HTH,
> Dennis
>
> On Thu, Oct 7, 2010 at 7:54 AM, 1Rnwb <[hidden 
> email]>
> wrote:
>
> >
> > Hi The reshape suggestions works great on my previous data, but I am
> unable
> > to make is work on the new dataset. It actually works but only gives me
> the
> > output of single row, instead of 96 rows.
> > The dataset has two control groups control 1 and control 2, two disease
> > groups viz disease 1 and disease 2 a total of 384 values
> > plate.idwell.id Group   HYB rlt1
> > P1  A1  control1SKOV3hyb0.19
> > P1  A2  disease1SKOV3hyb0.21
> > P1  A3  control1SKOV3hyb0.205
> > P1  A4  disease1SKOV3hyb0.206
> > P1  B1  disease2SKOV3hyb0.217
> > P1  B2  control2SKOV3hyb0.646
> > P1  B3  disease2SKOV3hyb0.371
> > P1  B4  control2SKOV3hyb0.56
> >
> > when I use
> > ydat <- reshape(ydat, idvar = c('plate.id','HYB'), timevar
> > ='Group',direction = 'wide')
> >
> > I get
> >
> > plate.idwell.id.control1HYB.control1rlt1.control1
> > well.id.disease1
> > HYB.disease1rlt1.disease1   well.id.disease2HYB.disease2
> >  rlt1.disease2
> > well.id.control2HYB.control2rlt1.control2
> > P1  A1  SKOV3hyb0.19A2  SKOV3hyb0.21
>  B1
> >  SKOV3hyb0.217   B2  SKOV3hyb0.646
> >
> >
> > instead of 96 rows of data, only one row comes, i tried new.row.names but
>
> > that is not working.
> > I would appreciate the help.
> > Thanks
> >
> > --
> > View this message in context:
> >
> http://r.789695.n4.nabble.com/subtraction-based-on-two-groups-in-a-dataframe-tp2716104p2966918.html
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > __
> > [hidden email] 
> > 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]]
>
> __
> [hidden email] 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.
>
>
> --
>  View message @
> http://r.789695.n4.nabble.com/subtraction-based-on-two-groups-in-a-dataframe-tp2716104p2967676.html
> To unsubscribe from subtraction based on two groups in a dataframe, cli

Re: [R] subtraction based on two groups in a dataframe

2010-10-07 Thread Dennis Murphy
Hi:

Is this what you were looking for?

plate.id well.id Group   HYB rlt1
P1  A1  control1SKOV3hyb0.19
P1  A2  disease1SKOV3hyb0.21
P1  A3  control1SKOV3hyb0.205
P1  A4  disease1SKOV3hyb0.206
P1  B1  disease2SKOV3hyb0.217
P1  B2  control2SKOV3hyb0.646
P1  B3  disease2SKOV3hyb0.371
P1  B4  control2SKOV3hyb0.56

dfwide <- reshape(df, idvar = c('plate.id', 'well.id', 'HYB'), timevar =
'Group',
  direction = 'wide')
> dfwide
  plate.id well.id  HYB rlt1.control1 rlt1.disease1 rlt1.disease2
1   P1  A1 SKOV3hyb 0.190NANA
2   P1  A2 SKOV3hybNA 0.210NA
3   P1  A3 SKOV3hyb 0.205NANA
4   P1  A4 SKOV3hybNA 0.206NA
5   P1  B1 SKOV3hybNANA 0.217
6   P1  B2 SKOV3hybNANANA
7   P1  B3 SKOV3hybNANA 0.371
8   P1  B4 SKOV3hybNANANA
  rlt1.control2
1NA
2NA
3NA
4NA
5NA
6 0.646
7NA
8 0.560


HTH,
Dennis

On Thu, Oct 7, 2010 at 7:54 AM, 1Rnwb  wrote:

>
> Hi The reshape suggestions works great on my previous data, but I am unable
> to make is work on the new dataset. It actually works but only gives me the
> output of single row, instead of 96 rows.
> The dataset has two control groups control 1 and control 2, two disease
> groups viz disease 1 and disease 2 a total of 384 values
> plate.idwell.id Group   HYB rlt1
> P1  A1  control1SKOV3hyb0.19
> P1  A2  disease1SKOV3hyb0.21
> P1  A3  control1SKOV3hyb0.205
> P1  A4  disease1SKOV3hyb0.206
> P1  B1  disease2SKOV3hyb0.217
> P1  B2  control2SKOV3hyb0.646
> P1  B3  disease2SKOV3hyb0.371
> P1  B4  control2SKOV3hyb0.56
>
> when I use
> ydat <- reshape(ydat, idvar = c('plate.id','HYB'), timevar
> ='Group',direction = 'wide')
>
> I get
>
> plate.idwell.id.control1HYB.control1rlt1.control1
> well.id.disease1
> HYB.disease1rlt1.disease1   well.id.disease2HYB.disease2
>  rlt1.disease2
> well.id.control2HYB.control2rlt1.control2
> P1  A1  SKOV3hyb0.19A2  SKOV3hyb0.21B1
>  SKOV3hyb0.217   B2  SKOV3hyb0.646
>
>
> instead of 96 rows of data, only one row comes, i tried new.row.names but
> that is not working.
> I would appreciate the help.
> Thanks
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/subtraction-based-on-two-groups-in-a-dataframe-tp2716104p2966918.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.


Re: [R] subtraction based on two groups in a dataframe

2010-10-07 Thread 1Rnwb

Hi The reshape suggestions works great on my previous data, but I am unable
to make is work on the new dataset. It actually works but only gives me the
output of single row, instead of 96 rows.
The dataset has two control groups control 1 and control 2, two disease
groups viz disease 1 and disease 2 a total of 384 values
plate.idwell.id Group   HYB rlt1
P1  A1  control1SKOV3hyb0.19
P1  A2  disease1SKOV3hyb0.21
P1  A3  control1SKOV3hyb0.205
P1  A4  disease1SKOV3hyb0.206
P1  B1  disease2SKOV3hyb0.217
P1  B2  control2SKOV3hyb0.646
P1  B3  disease2SKOV3hyb0.371
P1  B4  control2SKOV3hyb0.56

when I use
ydat <- reshape(ydat, idvar = c('plate.id','HYB'), timevar
='Group',direction = 'wide')

I get

plate.idwell.id.control1HYB.control1rlt1.control1   
well.id.disease1
HYB.disease1rlt1.disease1   well.id.disease2HYB.disease2
rlt1.disease2
well.id.control2HYB.control2rlt1.control2
P1  A1  SKOV3hyb0.19A2  SKOV3hyb0.21B1  
SKOV3hyb0.217   B2  SKOV3hyb0.646


instead of 96 rows of data, only one row comes, i tried new.row.names but
that is not working.
I would appreciate the help.
Thanks

-- 
View this message in context: 
http://r.789695.n4.nabble.com/subtraction-based-on-two-groups-in-a-dataframe-tp2716104p2966918.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.


Re: [R] subtraction based on two groups in a dataframe

2010-09-29 Thread 1Rnwb

Thanks for the help.
Sharad

On Mon, Sep 27, 2010 at 9:12 PM, Remko Duursma [via R] <
ml-node+2716469-935075351-6...@n4.nabble.com
> wrote:

> 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  A1ovca SKOV3hyb 0.184
> 386   P1  A2ovca SKOV3hyb 0.229
> 387   P1  A3ovca SKOV3hyb 0.214
> 388   P1  A4ovca SKOV3hyb 0.226
> 389   P1  A5ovca 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
>
> --
>  View message @
> http://r.789695.n4.nabble.com/subtraction-based-on-two-groups-in-a-dataframe-tp2716104p2716469.html
> To unsubscribe from subtraction based on two groups in a dataframe, click
> here.
>
>
>

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

[[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.


Re: [R] subtraction based on two groups in a dataframe

2010-09-28 Thread Dennis Murphy
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  A1ovca SKOV3hyb 0.184
+ 386   P1  A2ovca SKOV3hyb 0.229
+ 387   P1  A3ovca SKOV3hyb 0.214
+ 388   P1  A4ovca SKOV3hyb 0.226
+ 389   P1  A5ovca 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  A1SKOV3hyb0.190 SKOV3hyb 0.184
2   P1  A2SKOV3hyb0.210 SKOV3hyb 0.229
3   P1  A3SKOV3hyb0.205 SKOV3hyb 0.214
4   P1  A4SKOV3hyb0.206 SKOV3hyb 0.226
5   P1  A5SKOV3hyb0.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  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  A1ovca SKOV3hyb 0.184
> 386   P1  A2ovca SKOV3hyb 0.229
> 387   P1  A3ovca SKOV3hyb 0.214
> 388   P1  A4ovca SKOV3hyb 0.226
> 389   P1  A5ovca SKOV3hyb 0.217
> 390   P1  A6ovca 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  A1ovca SKOV3hyb 0.184   3.157895
> 386   P1  A2ovca SKOV3hyb 0.229  -9.047619
> 387   P1  A3ovca SKOV3hyb 0.214  -4.390244
> 388   P1  A4ovca SKOV3hyb 0.226  -9.708738
> 389   P1  A5ovca 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.


Re: [R] subtraction based on two groups in a dataframe

2010-09-27 Thread Remko Duursma

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  A1ovca SKOV3hyb 0.184 
386   P1  A2ovca SKOV3hyb 0.229 
387   P1  A3ovca SKOV3hyb 0.214 
388   P1  A4ovca SKOV3hyb 0.226 
389   P1  A5ovca 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
-- 
View this message in context: 
http://r.789695.n4.nabble.com/subtraction-based-on-two-groups-in-a-dataframe-tp2716104p2716469.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.


[R] subtraction based on two groups in a dataframe

2010-09-27 Thread 1Rnwb

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  A1ovca SKOV3hyb 0.184
386   P1  A2ovca SKOV3hyb 0.229
387   P1  A3ovca SKOV3hyb 0.214
388   P1  A4ovca SKOV3hyb 0.226
389   P1  A5ovca SKOV3hyb 0.217
390   P1  A6ovca 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  A1ovca SKOV3hyb 0.184   3.157895
386   P1  A2ovca SKOV3hyb 0.229  -9.047619
387   P1  A3ovca SKOV3hyb 0.214  -4.390244
388   P1  A4ovca SKOV3hyb 0.226  -9.708738
389   P1  A5ovca 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.