[R] replacing zeros by NAs

Mike Prager mike.prager at noaa.gov
Mon Jun 15 18:05:19 CEST 2009


Often, data are computed in real (not integer) numbers, and in
such cases, comparison to zero is not as good as using a
tolerance level. Modifying slightly the suggestions of others, I
would use something like this:

my.tol <- 1e-50
x <- c(1.4, 2.97, 1.0e-100, pi, 0.2, 5.1, 6.8, 0.0)
print(x)
is.na(x) <- abs(x) < my.tol
print(x)


-- 
Mike Prager, NOAA, Beaufort, NC
* Opinions expressed are personal and not represented otherwise.
* Any use of tradenames does not constitute a NOAA endorsement.




More information about the R-help mailing list