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
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
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
3 matches
Mail list logo