[R] Simulation

Greg Snow Greg.Snow at imail.org
Fri May 15 18:53:07 CEST 2009


I wrote "replicate" but the darn e-mail program "fixed" it for me.  I expected replicate to be a bit slower, but not by that amount.  I just wanted to include replicate as a more readable version of lapply while still improving over the loop approach.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: Ben Bolker [mailto:bolker at ufl.edu]
> Sent: Friday, May 15, 2009 10:19 AM
> To: Greg Snow
> Cc: r-help at r-project.org
> Subject: Re: [R] Simulation
> 
> Greg Snow wrote:
> > Another possibility (maybe more readable, gives the option of a list,
> probably not faster):
> >
> > Replicate(1000, rexp(15,1) )
> >
> 
>   I think that should be "replicate"
> 
>   The matrix form is quite a bit faster, but don't know if that will
> matter -- times below are for doing this task (1000 x 15 replicates)
> 1000 times ...
> 
> > system.time(replicate(1000,replicate(1000,rexp(15,1))))
>    user  system elapsed
>  12.689   0.220  12.985
> > system.time(replicate(1000,matrix(rexp(15000,1),ncol=15)))
>    user  system elapsed
>   2.512   0.452   2.976
> 
> 
> --
> Ben Bolker
> Associate professor, Biology Dep't, Univ. of Florida
> bolker at ufl.edu / www.zoology.ufl.edu/bolker
> GPG key: www.zoology.ufl.edu/bolker/benbolker-publickey.asc




More information about the R-help mailing list