Re: [R] From nested loop to mclapply

From: Allan Engelhardt <allane_at_cybaea.com>
Date: Mon, 18 Apr 2011 17:36:16 +0100

Try help("expand.grid", package="base") for one way to create the combinations of (i,j) outside the loop, or perhaps vignette("nested", package="foreach") which does it "automatically" (rather: naturally).

Allan

On 18/04/11 16:53, Alaios wrote:
> Dear all,
> I am trying to find a decent way to speed up my code.
>
> So far I have used mclapply with really good results (parallel version of lapply). I have a nested loop that I would like to help me convert it to lapply
>
> for (i in seq(from=-1,to=1-2/ncol(sr),length=ncol(sr))){
> for (j in seq(from=-1,to=1-2/nrow(sr),length=nrow(sr))){
> estimatedsr[findCoord(c(i,j),sr)[1],findCoord(c(i,j),sr)[2] ]<-fxy(c(i,j))
> }
>
> So far I have converted some one-depth for loops to lapply but I am not sure If I can use lapply to convert a nested loop to something simpler.
>
> Best Regards
> Alex
>
> ______________________________________________
> R-help_at_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.



R-help_at_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. Received on Mon 18 Apr 2011 - 16:38:01 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 19 Apr 2011 - 10:40:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive