Examine the sample function.
set.seed(1)
sample(c(0,1), size=12, replace=TRUE, prob=c(0.2,0.8))
1 1 1 0 1 0 0 1 1 1 1 1
sample takes a sample of the specified size from the components of x and in sample,
and the argument prob in sample is a vector of probability weights for obtaining the elements of the sampled vector.