[R] replace

Jeff Gentry jgentry at jimmy.harvard.edu
Fri Oct 11 20:36:36 CEST 2002


> The thing I need to do is to replace NA values with 0.
> But I;m not able to determine how to do it.

In what sort of structure?

A vector?
> a <- c(1,2,NA,3,4,NA,5,6,NA)
> a
[1]  1  2 NA  3  4 NA  5  6 NA
> a[!is.na(a)]
[1] 1 2 3 4 5 6

A list?
> a <- list(1,2,3,NA,4,5,NA,6,NA,7)
> a[!sapply(a,is.na)]
[[1]]
[1] 1

[[2]]
[1] 2

[[3]]
[1] 3

[[4]]
[1] 4

[[5]]
[1] 5

[[6]]
[1] 6

[[7]]
[1] 7

Something else?

-Jeff

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list