Re: [R] help with calculation from dataframe with multiple entries per sample

2012-09-19 Thread R. Michael Weylandt
On Wednesday, September 19, 2012, Jul_biologyGrad wrote: > Thanks everyone for the help! I pulled together a bunch of your suggestions > to get the result that I needed. I'm posting my final code below. Probably > not the most efficient way of doing things but gets the job done in a way > that a n

Re: [R] help with calculation from dataframe with multiple entries per sample

2012-09-18 Thread Jul_biologyGrad
Thanks everyone for the help! I pulled together a bunch of your suggestions to get the result that I needed. I'm posting my final code below. Probably not the most efficient way of doing things but gets the job done in a way that a newbie can understand! ##Here again is the example dataset Sample

Re: [R] help with calculation from dataframe with multiple entries per sample

2012-09-18 Thread William Dunlap
A.K. > > > > - Original Message - > From: Julie Lee-Yaw > To: "r-help@r-project.org" > Cc: > Sent: Monday, September 17, 2012 7:15 PM > Subject: [R] help with calculation from dataframe with multiple entries per > sample > > Hi >

Re: [R] help with calculation from dataframe with multiple entries per sample

2012-09-17 Thread David Winsemius
=length(unique(mydata$Sample))) Error in `$<-.data.frame`(`*tmp*`, "Gain", value = c(0.3, 0.3, 0.3, 0.101, : replacement has 9 rows, data has 10 > > > > > - Original Message - > From: Julie Lee-Yaw > To: "r-help@r-project.org&qu

Re: [R] help with calculation from dataframe with multiple entries per sample

2012-09-17 Thread arun
17, 2012 7:15 PM Subject: [R] help with calculation from dataframe with multiple entries per sample Hi  I have a dataframe similar to: >Sample<-c(1,1,1,2,2,2,3,3,3) >Time<-c(1,2,3,1,2,3,1,2,3) >Mass<-c(3,3.1,3.4,4,4.3,4.4,3,3.2,3.5) >mydata<-as.data.frame(cbind(Sample,T

Re: [R] help with calculation from dataframe with multiple entries per sample

2012-09-17 Thread arun
  2    3  4.4  0.1 #7  3    1  3.0  0.3 #8  3    2  3.2  0.3 #9  3    3  3.5  0.3 A.K. - Original Message - From: Julie Lee-Yaw To: "r-help@r-project.org" Cc: Sent: Monday, September 17, 2012 7:15 PM Subject: [R] help with calculation from dataframe with multipl

Re: [R] help with calculation from dataframe with multiple entries per sample

2012-09-17 Thread Rui Barradas
Or diff(x[2:3]) Rui Barradas Em 18-09-2012 01:05, David Winsemius escreveu: On Sep 17, 2012, at 5:00 PM, David Winsemius wrote: On Sep 17, 2012, at 4:15 PM, Julie Lee-Yaw wrote: Hi I have a dataframe similar to: Sample<-c(1,1,1,2,2,2,3,3,3) Time<-c(1,2,3,1,2,3,1,2,3) Mass<-c(3,3.1,3.4,4,4

Re: [R] help with calculation from dataframe with multiple entries per sample

2012-09-17 Thread David Winsemius
On Sep 17, 2012, at 5:00 PM, David Winsemius wrote: > > On Sep 17, 2012, at 4:15 PM, Julie Lee-Yaw wrote: > >> Hi >> >> I have a dataframe similar to: >> >>> Sample<-c(1,1,1,2,2,2,3,3,3) >> >>> Time<-c(1,2,3,1,2,3,1,2,3) >> >>> Mass<-c(3,3.1,3.4,4,4.3,4.4,3,3.2,3.5) >> >>> mydata<-as.data

Re: [R] help with calculation from dataframe with multiple entries per sample

2012-09-17 Thread David Winsemius
On Sep 17, 2012, at 4:15 PM, Julie Lee-Yaw wrote: > Hi > > I have a dataframe similar to: > >> Sample<-c(1,1,1,2,2,2,3,3,3) > >> Time<-c(1,2,3,1,2,3,1,2,3) > >> Mass<-c(3,3.1,3.4,4,4.3,4.4,3,3.2,3.5) > >> mydata<-as.data.frame(cbind(Sample,Time,Mass)) > Please tell me where you learned tha

Re: [R] help with calculation from dataframe with multiple entries per sample

2012-09-17 Thread Rui Barradas
Hello, Try the following. sp <- split(mydata, mydata$Sample) do.call(rbind, lapply(sp, function(x){x$Gain <- x$Mass[3] - x$Mass[2]; x})) Hope this helps, Rui Barradas Em 18-09-2012 00:15, Julie Lee-Yaw escreveu: > Hi > > I have a dataframe similar to: > >> Sample<-c(1,1,1,2,2,2,3,3,3) >> Time<-

Re: [R] help with calculation from dataframe with multiple entries per sample

2012-09-17 Thread Phil Spector
Julie - Since the apply functions operate on one row at a time, they can't do what you want. I think the easiest way to solve your problem is to reshape the data set, and merge it back with the original: dd = data.frame(Sample=c(1,1,1,2,2,2,3,3,3), + Time=c(1,2,3,1,2,3,1,

[R] help with calculation from dataframe with multiple entries per sample

2012-09-17 Thread Julie Lee-Yaw
Hi  I have a dataframe similar to: >Sample<-c(1,1,1,2,2,2,3,3,3) >Time<-c(1,2,3,1,2,3,1,2,3) >Mass<-c(3,3.1,3.4,4,4.3,4.4,3,3.2,3.5) >mydata<-as.data.frame(cbind(Sample,Time,Mass))   Sample Time Mass 1      1    1  3.0 2      1    2  3.1 3      1    3  3.4 4      2    1  4.0 5      2    2  4