0

I am trying to get a sequence of evenly spaced numbers between 0 and 1 in R. I am, however, running into an issue.

test <- seq(0, 1, by = 0.1)
test
test[2] == .1
test[4] == .3

Why does the first test of equality evaluate to TRUE while the second one evaluates to FALSE? Because I am later using the subset function within a Shiny app, I need test[4] to be exactly .3 for subsetting to work properly.

How can I do this? Also, can someone tell me why what I am doing is wrong, or is it a bug? The following works as expected:

test <- seq(0, 10, by = 1)
test
test[2] == 1
test[4] == 3
cdd
  • 505
  • 1
  • 4
  • 12

0 Answers0