bobby
bobby

Reputation: 183

How to count number of success of a binomial sample in R?

I'm not used to R but what I want to do is this in pseudo code

T = 0
F = 0
for (i in 1:1000) {
  successCount <- count(rbinom(1,100,0.6)==1)
  if(successCount >= 59)
      T = T + 1
  else
      F = F + 1
}

Trying to run a simulation without rerun / map.

successCount <- count(rbinom(1,100,0.6)==1) 

This part I've been searching but cant seem to find how to do this. Rest I think work

Upvotes: 0

Views: 1109

Answers (1)

user2974951
user2974951

Reputation: 10385

Something like this?

table(replicate(1000,ifelse(sum(rbinom(100,1,0.6)==1)>=59,1,0)))
  0   1 
374 626

where 0 represents F and 1 represents T.

Upvotes: 2

Related Questions