I understand your explanation about the test for even numbers.  However I am
still a bit confused as to how to go about finding a particular value.  Here
is an example data set

col #          attr1    attr2   attr 3    LON        LAT
17209         D        NA    NA -122.9409 38.27645
17210        BC        NA    NA -122.9581 38.36304
17211         B        NA    NA -123.6851 41.67121
17212        BC        NA    NA -123.0724 38.93073
17213         C        NA    NA -123.7240 41.84403
17214      <NA>       464    NA -122.9430 38.30988
17215         C        NA    NA -123.4442 40.65369
17216        BC        NA    NA -122.9389 38.31551
17217         C        NA    NA -123.0747 38.97998
17218         C        NA    NA -123.6580 41.59610
17219         C        NA    NA -123.4513 40.70992
17220         C        NA    NA -123.0901 39.06473
17221        BC        NA    NA -123.0653 38.94845
17222        BC        NA    NA -122.9464 38.36808
17223      <NA>       464    NA -123.0143 38.70205
17224      <NA>        NA     5 -122.8609 37.94137
17225      <NA>        NA     5 -122.8628 37.95057
17226      <NA>        NA     7 -122.8646 37.95978

If I wanted to find the row with Lat = 37.95978, how would i do that?  How
would  I find the rows with BC?

Thank you for all your help!

Mehdi Khan

On Tue, Jul 21, 2009 at 12:10 PM, Steve Lianoglou <
mailinglist.honey...@gmail.com> wrote:

> I am a bit confused as to what the following command does:
>> evens <- df$nums %% 2 == 0
>>
>
> It returns a logical vector (I'm calling this an "indexing vector") that is
> TRUE where df$nums %% 2 == 0 (%% is modulo division, and 4 mod 2 == 0 -- so
> it's a test for "being even")
>
>  In my matrix example, let's say I am looking for the variable(s) BC and I
>> want R to return all the rows with that value...
>>
>
> You "just" have to setup a suitable test and build an "indexing" vector to
> select the appropriate rows -- or use the subset function (see ?subset).
>
> If it's still confusing to you, please create a trivial example data.frame
> and send it back to the list along with things you'd like to "find", so we
> can give you concrete examples on different ways you can find what you need.
>
>  or If I want a value such as 33.543.  How would I get it to do that?
>> Just a single value in the latter case.  I have already converted it to a
>> data frame.
>>
>
> Be careful when searching for doubles/floats as sometimes you'll miss what
> you're looking for if you are using exact matches (ie something ==
> something.else) ... I have an almost.equals function in my "bag of
> utilities" that I'd probably use for stuff like this:
>
> almost.equal <- function(x, y, eps=0.000001) {
>  abs(x - y) < eps
> }
>
> '%~%' <- function(x, y) almost.equal(x, y))
>
> R> x <- rnorm(1000, sd=.0001)
> R> sum(x %~% 0)
> ## Equivalently: sum(almost.equal(x, 0))
> [1] 8
>
> R> sum(x == 0)
> [1] 0
>
> Summing over a logical vector treats the TRUE values as 1 and FALSE values
> as 0.
>
> HTH,
>
> -steve
>
> --
> Steve Lianoglou
> Graduate Student: Physiology, Biophysics and Systems Biology
> Weill Medical College of Cornell University
>
> Contact Info: 
> http://cbio.mskcc.org/~lianos/contact<http://cbio.mskcc.org/%7Elianos/contact>
>
>
>
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to