我是runnig rep()
函数并将一个对象作为参数传递给length.out参数
# Initialization
pop.seq <- seq(0.05,0.95,by=0.1)
for(pop.rate in pop.seq){
# Population vector
pop.neg.count <- ((1-pop.rate)*100)
pop.vec <- c(rep(1,length.out=pop.rate*100),rep(0,length.out = pop.neg.count))
# Loop 1's in split1
for(split11.count in 1:(pop.rate*100)){
# Loop 0's in split1
for(split10.count in 0:(100-(pop.rate*100)-1)){
# print values
---------
--------
---------
}
}
}
上述代码每次都会在第7次迭代时停止。 pop.vec只有99个元素&amp;以下将给出64的输出:
length(rep(0,length.out = pop.neg.count))
pop.neg.count也在控制台中显示65的值。
答案 0 :(得分:6)
我怀疑pop.neg.count
的值实际上不是65.例如,
R> pop.neg.count
[1] 65
R> length(rep(1, length.out=pop.neg.count))
[1] 64
然而,当打印出实际值时,我得
R> sprintf("%f", pop.neg.count)
[1] "64.999999990"
一开始,我设置了
pop.neg.count = 64.99999999