Re: [R] better loop for simulation

2016-06-18 Thread Dalthorp, Daniel
try: n.questions <- 10 # or however many you want mult.choice <- 2 scores <- rbinom(1000, size = n.questions, prob = 1/mult.choice) On Sat, Jun 18, 2016 at 3:12 PM, Naresh Gurbuxani < naresh_gurbux...@hotmail.com> wrote: > I want to calculate a function many times over. My solution below work

Re: [R] better loop for simulation

2016-06-18 Thread Duncan Murdoch
On 18/06/2016 6:12 PM, Naresh Gurbuxani wrote: I want to calculate a function many times over. My solution below works, but does not seem very elegant. # my function to run many times over stud.score <- function(n.questions, mult.choice = 2) { prob.success <- 1 / mult.choice an

Re: [R] better loop for simulation

2016-06-18 Thread jim holtman
use replicate: > stud.score <- function(n.questions, mult.choice = 2) { + prob.success <- 1 / mult.choice + answers <- (runif(n.questions) < prob.success) + return(sum(answers)) + } > > # create 1000 results > result <- replicate(1000, stud.score(10)) > > # look at hist