Re: [R] loop function within a loop

2011-10-12 Thread William Dunlap
roject.org] On > Behalf Of Sally Zhen > Sent: Wednesday, October 12, 2011 7:56 AM > To: r-help@r-project.org > Subject: [R] loop function within a loop > > Hi all, > > I'm working on a loop function for a large dataset which contains 1000 > different groups. I would

Re: [R] loop function within a loop

2011-10-12 Thread David Winsemius
On Oct 12, 2011, at 10:55 AM, Sally Zhen wrote: Hi all, I'm working on a loop function for a large dataset which contains 1000 different groups. I would like to reconstruct the order of events within each group by using a loop function in R. Not generally a good first strategy in R. (Cu

Re: [R] loop function within a loop

2011-10-12 Thread Weidong Gu
It's better to avoid loop in this situation. If you want to reorder subsets of the data based on event, the follow works df<-read.table('clipboard',header=TRUE) sp.or<-lapply(split(df,df$group),function(ldf) ldf[order(ldf$event),]) new.df<-do.call('rbind',sp.or) Weidong Gu On Wed, Oct 12, 2011 a

[R] loop function within a loop

2011-10-12 Thread Sally Zhen
Hi all, I'm working on a loop function for a large dataset which contains 1000 different groups. I would like to reconstruct the order of events within each group by using a loop function in R. (Currently the order of events are based on the ascending order of prev_event within the group) A demo