Finally I ended up doing this: temp <- expand.grid(1:n,1:n) temp<-temp[temp[,1]>temp[,2]]
apply(temp,1, ... ) and it seems much faster :) On Sat, Jun 27, 2009 at 3:26 PM, Patrick Burns<pbu...@pburns.seanet.com> wrote: > See 'The R Inferno'. > > > > Patrick Burns > patr...@burns-stat.com > +44 (0)20 8525 0696 > http://www.burns-stat.com > (home of "The R Inferno" and "A Guide for the Unwilling S User") > > > Hesen Peng wrote: >> >> My dear R buddies, >> >> I'm writing a loop program like this: >> >> for(i in 1:n){ >> for(j in 1:i){ >> ... >> } >> } >> >> I wonder if there is any simple apply()-like function to make the loop >> a little bit easier and faster. Thanks a lot. >> >> Best wishes, >> > -- 彭河森 Hesen Peng http://hesen.peng.googlepages.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.