[R] NA preserved in logical call - I don't understand this behavior because NA is not equal to 0

stephen sefick ssefick at gmail.com
Sun Jul 18 18:02:32 CEST 2010


I am confused by the behavior of the below piece of code.  The NAs are
making it past the logical call ==0.  I am sure that I am missing
something.  I just don't understand this behavior.  Thanks for your
help in advance.


########code#######################################################
left <- (structure(list(measurment_num = c(2, 2.2, 2.4, 2.6, 2.8, 2.82,
3, NA, NA, NA), bankfull_depths_m = c(1.29, 1.28, 1.23, 0.18,
-0.05, 0, -0.09, NA, NA, NA)), .Names = c("measurment_num", "bankfull_depths_m"
), row.names = c(10L, 11L, 12L, 13L, 14L, 20L, 15L, 16L, 17L,
18L), class = "data.frame"))

if(sum(left[,"bankfull_depths_m"]==0, na.rm=TRUE) == 1){
left_min <- left[left[,"bankfull_depths_m"]==0, "measurment_num"]
}

left
##################################################################

-- 
Stephen Sefick
____________________________________
| Auburn University                                   |
| Department of Biological Sciences           |
| 331 Funchess Hall                                  |
| Auburn, Alabama                                   |
| 36849                                                    |
|___________________________________|
| sas0025 at auburn.edu                             |
| http://www.auburn.edu/~sas0025             |
|___________________________________|

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

                                -K. Mullis



More information about the R-help mailing list