r - Why am I not getting the index value of a matrix using the which function? -


i have matrix of thousands of coordinate values. , want find index of chosen value. use this:

which(long == -118.1123, arr.ind=true) 

but don't value. blank row , column. however, when this, values.

which(long < -118.1123, arr.ind=true) 

i know value exists because have manually checked in rstudio pane printed out value using long[1,2] etc.

dput(long) doesn't work matrices. hope can help.

diagnosis per comments

 - long[1,1]  [1] -118.0981  - long[1,1]==-118.0981 [1] false 

here's example of using test allows "fuzz-factor" difference ignored:

> m <- matrix(rnorm(10) , 5,2) > m            [,1]       [,2] [1,] -0.2382021  2.1698010 [2,] -1.1617644 -1.1513516 [3,]  1.3597808  0.9365208 [4,]  0.7460694 -1.7216410 [5,] -0.2413117 -0.1780468 > which(m==-0.2382021, arr.ind=true)      row col > which(abs(m - -0.2382021) < 0.0000001, arr.ind=true)      row col [1,]   1   1 

my comment suggesting all.equal didn't work matrix argument inside which. checked @rhertel's choice of signif , succeed.

> which(signif(m,7) == -0.2382021, arr.ind=true)      row col [1,]   1   1 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -