Jason Turner <[EMAIL PROTECTED]> writes:
> On Mon, Jan 13, 2003 at 05:15:02PM +0000, juan pablo perez wrote:
> > what should I do to replace in a data frame NA�s with zeroes?
>
> I use lapply
>
> > dd <- data.frame(a=c(1,2,NA,4),b=c(NA,2,3,4))
> > dd
> a b
> 1 1 NA
> 2 2 2
> 3 NA 3
> 4 4 4
> > dd2 <- data.frame(lapply(dd,function(x,...){x[is.na(x)] <- 3.14159 ; x}))
Slightly neater:
dd2 <- dd
dd2[] <- lapply(dd2,function(x) replace(x, is.na(x), 3.14159))
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907
______________________________________________
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help