Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想从二项式 1 或 2 生成随机数,而不是通常的 0 和 1。通常我们将使用rbinom(10, 1, 0.4)生成 0 或 1,但是否可以生成 1 和 2?或者有什么办法可以转换吗?
rbinom(10, 1, 0.4)
你可以做:
rbinom(10, 1, 0.4) + 1
或使用示例:
sample(1:2, 10, prob=c(0.6,0.4), replace=TRUE)