2016-03-16 47 views
-2

我很困惑......思考這個錯誤是真的嗎?怎麼會這樣? 我只想做一個0和1的矢量。這個R bug是真的嗎?

這裏的源和結果

n.subj=1000 
prop.aber = 0.9 
n.measure = 3 
n.subj.norm = n.subj*(1-prop.aber) 
n.subj.aber = n.subj*prop.aber 
labE <- rnorm(n.subj*n.measure, 0, 1) 
labT_ <- c(rep(0, n.subj.norm), rep(1, n.subj.aber)); length(labT_) 
sum(labT_ == 0); sum(labT_ == 1) 


[1] 99 
[1] 900 

我的常識告訴我,它應該是100和900 !!!!!!?!?!?????

+1

請參見'幫助(「樣本「)'爲你實際上想要達到的目標。這裏沒有錯誤。 – Roland

回答

1

由於浮點問題,n.subj.norm是不完全的100見this後獲取更多信息

請參閱下面的例子:

n.subj.norm == 100 
# FALSE 
length(rep(0, 100)) 
# 100 
length(rep(0, n.subj.norm)) 
# 99 
length(rep(0, round(n.subj.norm, 0))) 
# 100 
+1

另請參見:class(n.subj.norm); as.integer(n.subj.norm)' – Roland

+0

非常令人震驚。我從來沒有想過這會導致任何問題,比如代表旁邊的比較...... –