Skip to content
Prev 307404 / 398506 Next

simulating a toss of a coin

Hello,

Try the following.


fun <- function(n = 100){
     x <- sample(c("H","T"),3*n,replace=TRUE)
     dim(x) <- c(3,n)
     num_heads <- apply(x,2,function(x) sum(x=="H"))
     table(num_heads)/n
}

Runs <- 1e1
t(replicate(Runs, fun()))

Hope this helps,

Rui Barradas
Em 09-10-2012 06:04, David Arnold escreveu: