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}))
> dd2
        a       b
1 1.00000 3.14159
2 2.00000 2.00000
3 3.14159 3.00000
4 4.00000 4.00000

That will generate a warning message for each non-numeric column in
your data frame.  A tidier way is left as an exercise. ;)

Cheers

Jason
-- 
Indigo Industrial Controls Ltd.
64-21-343-545
[EMAIL PROTECTED]

______________________________________________
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help

Reply via email to