[R] From nested loop to mclapply
Allan Engelhardt
allane at cybaea.com
Mon Apr 18 18:36:16 CEST 2011
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.
More information about the R-help
mailing list