Skip to content

Iteration in R

9 messages · Martin Zonyrah, David Winsemius, andrija djurovic +2 more

#
On Dec 3, 2011, at 1:10 PM, Martin Zonyrah wrote:

            
?replicate
==

David Winsemius, MD
West Hartford, CT
#
? replicate

or a for loop

or do all one hundred simulations at once

x <- matrix(rnorm(100^2, 1, 2), 100)

It's going to depend on what you want to do with the numbers.

Michael
On Sat, Dec 3, 2011 at 1:10 PM, Martin Zonyrah <martin2005z at yahoo.com> wrote:
#
Hi Michael, 
How would you do this with lapply to return a list?
I can't seem to get that to work (I haven't used these much and am trying to
learn).
Thanks
Brad


Michael Weylandt wrote
--
View this message in context: http://r.789695.n4.nabble.com/Iteration-in-R-tp4154433p4154479.html
Sent from the R help mailing list archive at Nabble.com.
#
Interesting and thank you; I'm confused as to why this doesn't work with: 

lapply(rep(1,6), FUN=rnorm, n=10, mean=1.0, sd=1) 



andrija djurovic wrote
--
View this message in context: http://r.789695.n4.nabble.com/Iteration-in-R-tp4154433p4154559.html
Sent from the R help mailing list archive at Nabble.com.
#
And with replicate:

replicate(100, rnorm(100, 1,2), simplify = FALSE)


Michael
On Sat, Dec 3, 2011 at 2:38 PM, andrija djurovic <djandrija at gmail.com> wrote:
#
Because lapply() tries to pass an argument to FUN and there's none
that it can receive.

This would work however:

lapply(rep(100, 6), rnorm, mean = 1, sd = 2)

Michael
On Sat, Dec 3, 2011 at 2:42 PM, B77S <bps0002 at auburn.edu> wrote: