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 number of values 'numval' which is derived from the length of the vector 'Prob'. 'Prob' is giving me probability value that each individual point will be 0 or 1. So in this instance first number will have prob value of 0.9 being 1, and 0.1 being 0. And so on. Then, I would like to repeat random sample generation 1000 times. I have a script (below) generating random 0 and 1's but I am missing component on giving the probability values. Help will be much appreciated - I am fairly new to R.
Prob <- c(0.9, 0.3, 0.6, 0.8, 0.23, 0.45, 0.1, 0.3, 0.5, 0.03)
RandomSample <- list()
zeroones <- c(0,1)
rep = 1000
numval <- length(Prob)
for (i in 1:rep) RandomSample[[i]] <- c(sample(zeroones,numval,replace = TRUE))
t(sapply(RandomSample, unlist, simplify = TRUE))
for (i in 1:rep) RandomSample[[i]] <- c(sample(zeroones,numval,prob = Prob[i],replace = TRUE))
– Sangram