Re: [R] Problem with POSIXct in ave

2010-08-20 Thread Gabor Grothendieck
On Fri, Aug 20, 2010 at 3:09 PM, Gabor Grothendieck wrote: > On Fri, Aug 20, 2010 at 10:56 AM, Sasha Hafner wrote: >> Hi, >> >> I am having trouble using the ave function with a POSIXct object. For >> example: >> >> x<-Sys.time()+0:9*3600 >> dat<-data.frame(id=rep(c('a',' >> b','c'),each=10),dt=r

Re: [R] Problem with POSIXct in ave

2010-08-20 Thread Gabor Grothendieck
On Fri, Aug 20, 2010 at 10:56 AM, Sasha Hafner wrote: > Hi, > > I am having trouble using the ave function with a POSIXct object. For > example: > > x<-Sys.time()+0:9*3600 > dat<-data.frame(id=rep(c('a',' > b','c'),each=10),dt=rep(x,3),i=rep(1:10,3)) > dat > > # This is what I want to do: > dat$ti

Re: [R] Problem with POSIXct in ave

2010-08-20 Thread David Winsemius
On Aug 20, 2010, at 10:56 AM, Sasha Hafner wrote: Hi, I am having trouble using the ave function with a POSIXct object. For example: x<-Sys.time()+0:9*3600 dat<-data.frame(id=rep(c('a',' b','c'),each=10),dt=rep(x,3),i=rep(1:10,3)) dat # This is what I want to do: dat$time.elapsed<-unsplit(la

[R] Problem with POSIXct in ave

2010-08-20 Thread Sasha Hafner
Hi, I am having trouble using the ave function with a POSIXct object. For example: x<-Sys.time()+0:9*3600 dat<-data.frame(id=rep(c('a',' b','c'),each=10),dt=rep(x,3),i=rep(1:10,3)) dat # This is what I want to do: dat$time.elapsed<-unsplit(lapply(split(dat$dt,dat$id),function(x) x-x[1]),f=dat$id