[R] Searching for specific values in a matrix

Steve Lianoglou mailinglist.honeypot at gmail.com
Tue Jul 28 18:48:29 CEST 2009


> quick question, i am trying to get an interval of values now with  
> this code by toggling the tolerance limit.  is there any way i can  
> modify this code to find values which are within limits of BOTH  
> latitude and longitude?  currently i have to pick one or the other.

It's not really clear where your data is lat/long .. is this x/y?

Anyway, you can "&" two "query vectors" to get the data that's between  
both. For instance:

rearranged[1:10, 1:5]
           x        y band1 VSCAT.001 soiltype
1  -124.3949 40.42468    NA        NA       CD
2  -124.3463 40.27358    NA        NA       CD
3  -124.3357 40.25226    NA        NA       CD
4  -124.3663 40.40241    NA        NA       CD
5  -124.3674 40.49810    NA        NA       CD
6  -124.3083 40.24744    NA       464     <NA>
7  -124.3017 40.31295    NA        NA        D
8  -124.3375 40.47557    NA       464     <NA>
9  -124.2511 40.11697     1        NA     <NA>
10 -124.2532 40.12640     1        NA     <NA>

Assume you want a range constrained by x and y:

good.x <- rearranged$x > 124.3 & rearranged$x < 125
good.y <- rearranged$y > 40.5 & rearranged$y < 41

rearranged[good.x & good.y,]

Like that?

-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
   |  Memorial Sloan-Kettering Cancer Center
   |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact




More information about the R-help mailing list