Generate Vectors only Contains 0 And 1 in R
You can generate a vector only containing 0 and 1 in R using sample() and rbinom() functions. sample: sample(c(0, 1), size = 10, replace = TRUE) rbinom: rbinom(10, size = 1, prob = 0.5) In both sample() and rbinom(): Example 1 The following is the output. > print(vector_1) [1] 0 0 1 1 1 1 … Read more