-2

I am quite confused... and thinking is this bug real? How can it be? I just want to make a vector of 0's and 1's.

Here's the source and the outcome

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 

My common sense tells me that it should be 100 and 900!!!!!!?!?!?????

KH Kim
  • 1,155
  • 1
  • 7
  • 14

1 Answers1

1

Due to the floating point issues, n.subj.norm is not exactly 100. See this post for more information

See the below for an example:

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
Community
  • 1
  • 1
Raad
  • 2,675
  • 1
  • 13
  • 26