I am trying to write a function that sets a lower level cutoff"
trunc1 <- function(x,threshold) ifelse(x<=threshold,0,x)
df<-data.frame(a=seq(0,1,0.1),b=seq(0.05,1.05,0.1))
when I run:
trunc1(df$a,0.5)
I get
0.0 0.0 0.0 0.0 0.0 0.0 0.6 0.7 0.8 0.9 1.0
which is what I expect. However,
trunc1(df$a,0.6)
returns
0.0 0.0 0.0 0.0 0.0 0.0 0.6 0.7 0.8 0.9 1.0
I am surprised by this since 0.6<=0.6 the ifelse function should have returned 0 not 0.6. I know this should be simple.
x<-seq(0,1,0.1)<=0.6
names(x)<-seq(0,1,0.1)
returns
   0   0.1   0.2   0.3   0.4   0.5   0.6   0.7   0.8   0.9     1 
TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE 
version
               _
platform       x86_64-apple-darwin15.6.0
arch           x86_64
os             darwin15.6.0
system         x86_64, darwin15.6.0
status
major          3
minor          4.3
year           2017
month          11
day            30
svn rev        73796
language       R
version.string R version 3.4.3 (2017-11-30)
nickname       Kite-Eating Tree 
