[R] Long for Loop- calling C from R - Parallel Computing

Karl Ove Hufthammer karl at huftis.org
Mon Oct 5 15:48:59 CEST 2009


In article <6f6f0fd60910050629p28c99209jcd7836353fd2d754
@mail.gmail.com>, antonioparedes14 at gmail.com says...
> I'm running the following for loop to generate random variables in chunks of
> 60 at a time (l), here h is of order in millions (could be 5 to 6 millions),
> note that generating all the variables at once could have an impact on the
> final results

No, it will not. See this example code for an illustration:

set.seed(1)
rnorm(3)
rnorm(3)
set.seed(1)
rnorm(6)

So if you generate the six numbers three at a time or all at once gives 
exactly the same result.

So my suggestion is to generate all the numbers at once. That takes next 
to no time. Or, if it takes too much memory, generate for example a 
million at once, and repeat a few times.

-- 
Karl Ove Hufthammer



More information about the R-help mailing list