我想创建一个值在1到10之间的随机整数向量,随着向量的前进,出现更高数字的可能性逐渐增加.但是,我仍然希望这些值混合在一起,也就是说,我试图避免1,1,1,1,2,2,2,3... etc
到目前为止,我已经做到了以下几点,这是可行的,但肯定有一种更优雅的方式来实现这一点?
# Generate 3 vectors of 1000 random integers, each with slightly different distributions
LOW <- rpois(1000, 2)
MID <- rpois(1000, 4)
HIGH <- rpois(1000, 7)
# Remove any values outside the desired range of 1:10
LOW <- LOW[LOW>0 & LOW<11]
MID <- MID[MID>0 & MID<11]
HIGH <- HIGH[HIGH>0 & HIGH<11]
# Sample 200 values from each vector
LOW <- sample(LOW, 200)
MID <- sample(MID, 200)
HIGH <- sample(HIGH, 200)
# Combine into a single vector
COMBINED <- c(LOW, MID, HIGH)
# Check distribution
X <- 1:600
plot(COMBINED)
lines(predict(lm(COMBINED~X)), col='red', lwd = 6)