[R] Replacing all NA values in a matrix

John Fox jfox at mcmaster.ca
Wed Jan 5 16:08:20 CET 2005


Dear Michael,

A[is.na(A)] <- value

I hope this helps,
 John

--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
-------------------------------- 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of 
> michael watson (IAH-C)
> Sent: Wednesday, January 05, 2005 9:26 AM
> To: R-help at stat.math.ethz.ch
> Subject: [R] Replacing all NA values in a matrix
> 
> OK, dumb question, and it is probably in the docs somewhere, but after
> 12 months working with R and quite a while looking at the 
> docs, I still don't know (or have forgotten) how to replace 
> all NA values in a matrix at once with some other value.  I 
> can do it column by column using is.na(), but I can't figure 
> out how to do it for the whole matrix.  My apologies, I am ashamed ;-)
> 
> Michael Watson




More information about the R-help mailing list