[R] Replacing all NA values in a matrix
Dimitris Rizopoulos
dimitris.rizopoulos at med.kuleuven.ac.be
Wed Jan 5 15:58:05 CET 2005
Hi Michael,
try this:
mat <- matrix(1:25, 5, 5)
mat[sample(25, 10)] <- NA
mat
#####
mat[is.na(mat)] <- 100
mat
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
----- Original Message -----
From: "michael watson (IAH-C)" <michael.watson at bbsrc.ac.uk>
To: <R-help at stat.math.ethz.ch>
Sent: Wednesday, January 05, 2005 3:26 PM
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