[R] Simulation
Peter Flom
peterflomconsulting at mindspring.com
Thu May 14 12:16:50 CEST 2009
Wacek Kusnierczyk <Waclaw.Marcin.Kusnierczyk at idi.ntnu.no> wrote
>> Seriously? You think:
>>
>> lapply(1:n, rnorm, 0, 1)
>>
>> is 'clearer' than:
>>
>> x=list()
>> for(i in 1:n){
>> x[[i]]=rnorm(i,0,1)
>> }
>>
>> for beginners?
>>
>> Firstly, using 'lapply' introduces a function (lapply) that doesn't
>> have an intuitive name. Also, it takes a function as an argument. The
>> concept of having a function as a parameter to another function is
>> something that a lot of programming beginners have trouble with -
>> unless they were brought up on LISP of course, and few of us are.
>>
>> I propose that the for-loop example is clearer to a larger population
>> than the lapply version.
>
As a beginner, I agree .... the for loop is much clearer to me.
Peter
Peter L. Flom, PhD
Statistical Consultant
www DOT peterflomconsulting DOT com
More information about the R-help
mailing list