NA preserved in logical call - I don't understand this behavior because NA is not equal to 0
On 18.07.2010 18:02, stephen sefick wrote:
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"]
}
NA == 0 is ??? --> NA! Use is.na() to check for missing values. Uwe Ligges
left ##################################################################