Generating random numbers (0 and 1) given specific probability values in R

后端 未结 2 623
梦谈多话
梦谈多话 2021-01-14 12:34

I could not find answer for this question in R. I would like to generate a random sample of 0 to 1\'s \'RandomSample\'. For each sample I would like to have a specific numbe

2条回答
  •  萌比男神i
    2021-01-14 12:48

    You could use rbinom():

    Prob <- c(0.9, 0.3, 0.6, 0.8, 0.23, 0.45, 0.1, 0.3, 0.5, 0.03) #specify vector of probabilities
    niter<- 1000 #number of iterations
    randomSample<-rbinom(niter,1,prob=rep(Prob,niter)) #randomly sample from binomial with vector of probabilities. 
    

提交回复
热议问题