3

I am at my wits end. I am shocked that I am getting this problem in R that I am unable to fix for last 3 hours. Please help

df$time
   [1]  0.00  0.01  0.02  0.03  0.04  0.05  0.06  0.07  0.08  0.09  0.10
  [12]  0.11  0.12  0.13  0.14  0.15  0.16  0.17  0.18  0.19  0.20  0.21
  [23]  0.22  0.23  0.24  0.25  0.26  0.27  0.28  0.29  0.30  0.31  0.32
  [34]  0.33  0.34  0.35  0.36  0.37  0.38  0.39  0.40  0.41  0.42  0.43
  [45]

Now I do

which(df$time == 0.35)
integer(0) # Why do I get this null here, it should be 36

But when I do

 which(df$time == 0.33)
[1] 34

or

which(df$time == 0.36)
[1] 37

or

 which(df$time == 0.34)
[1] 35

What is the problem with 0.35?

EDIT:

options()[c("scipen","digits")]
$scipen
[1] 0

$digits
[1] 7

and

class(df$time)
[1] "numeric"
which(as.numeric(df$time) == 0.35)
integer(0)

EDIT : Requested output

dput(df$time[1:40]) 
c(0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 
0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 
0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 
0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39)
Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
  • 2
    Please add the output of `dput(df$time)` to you question to make this reproducible. – Matt Summersgill Mar 26 '20 at 13:17
  • 1
    Hi Hamda, please also provide the output of `options()[c("scipen","digits")]`. – Ian Campbell Mar 26 '20 at 13:21
  • What is the output of `class(df$time)`? Does the result change if you format your query number accordingly: in other words, can you force the value in `which(df$time == value)` to be `as.xxx`, where `xxx` is the class of the `df$time` object? – chemdork123 Mar 26 '20 at 13:24
  • Added outputs as requested. Could not do dput as stackoverflow limits the quantity of code in the question. Thank you in advance. – Hamda Binte Ajmal Mar 26 '20 at 13:25
  • Hi @HamdaBinteAjmal, looks like it should work. Yeah your df is huge, but for your problem, do this dput(df$time[1:40]) and paste that output. – StupidWolf Mar 26 '20 at 13:28
  • dput is there now – Hamda Binte Ajmal Mar 26 '20 at 13:29
  • I get the same thing! Use this as the sample dataset: `t <- seq(0, 0.43, by=0.01)`. When I try `which(t==0.33)`, I get 34. When I try `which(t==0.35)`, I get `integer(0)`. When I explicitly state it I still get the same result: `which(t[36]==0.35)`. What's going on? – chemdork123 Mar 26 '20 at 13:33
  • alrite, if you look at the supposedly duplicated question above, it goes like this, if you had done some operations to get df$time, there is a difference in the scalar and you can look at why. You can use all.equal.. I don't quite know how you derived df$time, but most likely this is the reason – StupidWolf Mar 26 '20 at 13:38
  • 1
    Yes I found the answer from the duplicated question marked above. What a waste of 4 hours work . Thanks everyone – Hamda Binte Ajmal Mar 26 '20 at 13:55

0 Answers0