Re: [R] Re membering the last time an event occurred within a dataframe

2008-07-03 Thread Jim Price
Many thanks; using Gabor's advice I'd used: with(myData, rep(time, evid)[cumsum(evid)]) but yours also works a treat Henrique. Thanks once again! Jim. Henrique Dallazuanna wrote: > > If I understand, try this: > > with(myData, factor(cumsum(evid), labels = which(evid == 1))) > > > On Th

Re: [R] Re membering the last time an event occurred within a dataframe

2008-07-03 Thread Duncan Murdoch
On 7/3/2008 2:19 PM, Jim Price wrote: All, I am constructing a pharmacokinetic dataset and have hit a snag. The dataset can be demonstrated in the following way: myData <- data.frame( evid = c(1, 0, 0, 0, 1, 0, 1, 1, 1, 0), time = 1:10, last.dose.time = c(1, 1, 1, 1, 5, 5, 7, 8, 9

Re: [R] Re membering the last time an event occurred within a dataframe

2008-07-03 Thread Henrique Dallazuanna
If I understand, try this: with(myData, factor(cumsum(evid), labels = which(evid == 1))) On Thu, Jul 3, 2008 at 3:19 PM, Jim Price <[EMAIL PROTECTED]> wrote: > > All, > > I am constructing a pharmacokinetic dataset and have hit a snag. The > dataset > can be demonstrated in the following way: >

Re: [R] Re membering the last time an event occurred within a dataframe

2008-07-03 Thread Gabor Grothendieck
Try: cumsum(myData$evid) On Thu, Jul 3, 2008 at 2:19 PM, Jim Price <[EMAIL PROTECTED]> wrote: > > All, > > I am constructing a pharmacokinetic dataset and have hit a snag. The dataset > can be demonstrated in the following way: > > > > myData <- data.frame( >evid = c(1, 0, 0, 0, 1, 0, 1,

[R] Re membering the last time an event occurred within a dataframe

2008-07-03 Thread Jim Price
All, I am constructing a pharmacokinetic dataset and have hit a snag. The dataset can be demonstrated in the following way: myData <- data.frame( evid = c(1, 0, 0, 0, 1, 0, 1, 1, 1, 0), time = 1:10, last.dose.time = c(1, 1, 1, 1, 5, 5, 7, 8, 9, 9) ) The evid field is