0

The answer to this question maybe very simple but I cannot think of obvious reasons for this.

Why does rep(1,40*(1-0.8)) result in vector of length 7 instead of 8? Anyone please.

AnilGoyal
  • 25,297
  • 4
  • 27
  • 45

1 Answers1

2

It's due to floating point precision:

print(40*(1-0.8), digits = 20)
## [1] 7.9999999999999982

round can be used:

rep(1, round(40*(1-0.8)))
## [1] 1 1 1 1 1 1 1 1
G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341