1

I have a very basic question. I define a simple sequence:

numbers=seq(0.001,0.5,0.001)

now I want to know which element of this sequence has value 0.01, I tried this:

which(numbers==0.01)

but I just get

integer(0)

asking for the 10th elment gives me

numbers[10]
[1] 0.01

But

numbers[10]==0.01 
[1] FALSE

Can it have something to do with the places behind the decimal point? How can I get the element (here:10), that matches a certain value? (here: 0.1)?

Thank you.

Mathias
  • 11
  • 2
  • Try `which(round(numbers,3) == .01)` This link [Why are these numbers not equal?](http://stackoverflow.com/questions/9508518/why-are-these-numbers-not-equal) May help explain why – Pierre L Jul 14 '15 at 15:17
  • THANK YOU SO MUCH!!!! I couldn't figure this out for the longest time! Rounding works. – user3431218 May 12 '20 at 20:54

0 Answers0