[R] R will not find certain entries in an array created by an interval

arun smartpink111 at yahoo.com
Thu Aug 22 04:49:27 CEST 2013


Hi,
Please check:
?FAQ 7.31
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f

 intervalloweredge[3]-3.845
#[1] -4.440892e-16


which(as.character(intervalloweredge)=="3.845")
#[1] 3
which(as.character(intervalloweredge)=="3.86")
#[1] 4

#or
which(round(intervalloweredge,3)==3.845)
#[1] 3


A.K.

Greetings 

I am trying to create an interval list as follows: 

interval <- 0.015 
intervalloweredge <- 3.815+interval*seq(0,5, by=1) 
intervalupperedge <- intervalloweredge + interval 

Here is the output when I type intervalloweredge: 

[1] 3.815 3.830 3.845 3.860 3.875 3.890 

All seems well... 

but then R won't find intervalloweredge[3]: 

which(intervalloweredge==3.815) 
[1] 1 
> which(intervalloweredge==3.83) 
[1] 2 
> which(intervalloweredge==3.845) 
integer(0) 
> which(intervalloweredge==3.86) 
[1] 4 
> which(intervalloweredge==3.875) 
[1] 5 
> which(intervalloweredge==3.89) 
[1] 6 


Likewise 
Here is the output when I type intervalupperedge: 

[1] 3.830 3.845 3.860 3.875 3.890 3.905 

but then R won't find intervalupperedge[6]: 

> which(intervalupperedge==3.83) 
[1] 1 
> which(intervalupperedge==3.845) 
[1] 2 
> which(intervalupperedge==3.86) 
[1] 3 
> which(intervalupperedge==3.875) 
[1] 4 
> which(intervalupperedge==3.89) 
[1] 5 
> which(intervalupperedge==3.905) 
integer(0) 



Instead, I have to define the intervals by hand, like this: 

alt <- 0.015 
altlower <- c(3.815, 3.83, 3.845, 3.86, 3.875, 3.89) 
altupper <- c(3.83, 3.845, 3.86, 3.875, 3.89, 3.905) 

Then R will find each entry in both arrays fine. 


What's going on? Why can't I use the "interval" variables in the way that I've set them up? 




Also, 

I received a message saying that I needed to subscribe, before my post would be accepted. 

I tried clicking on the Subscribe button and was taken to a page where I was asked to check my email for a subscription confirm. 

But I never received the email. 

Did my post get accepted? How do I know? Because I have posts in other threads from months back that have yet to be accepted.



More information about the R-help mailing list