[R] Replacing all NA values in a matrix
Wiener, Matthew
matthew_wiener at merck.com
Wed Jan 5 16:15:55 CET 2005
Michael --
is.na works on the full matrix. The commands below construct a matrix,
insert some NA's, and then convert them all to 0.
> temp1 <- matrix(runif(25), 5, 5)
> temp1[temp1 < 0.1] <- NA
> temp1[is.na(temp1)] <- 0
Hope this helps.
Regards,
Matt Wiener
-----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
Head of Informatics
Institute for Animal Health,
Compton Laboratory,
Compton,
Newbury,
Berkshire RG20 7NN
UK
Phone : +44 (0)1635 578411 ext. 2535
Mobile: +44 (0)7990 827831
E-mail: michael.watson at bbsrc.ac.uk
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list