在…工作
R
,我需要创建一个长度向量
n
从泊松分布中随机抽取值,λ=1,但下限为2,上限为6(即所有数字将为2、3、4、5或6)。
我不知道怎么做。我试着创造一个
for
循环,该循环将用该范围内的值替换该范围外的任何值:
seed(123)
n<-25 #example length
example<-rpois(n,1)
test<-example #redundant - only duplicating to compare with original *example* values
for (i in 1:length(n)){
if (test[i]<2||test[i]>6){
test[i]<-rpois(1,1)
}
}
但这似乎不起作用(仍然得到0和1,等等)
test
). 任何想法都将不胜感激!