[R] removing missing values from a matrix

Amit Kumar amitkumartiwary at gmail.com
Thu Oct 1 19:54:29 CEST 2009


Hi! All,
I am working with a large matrix of dimension 23689 x 162. Some of the
values of this matrix is missing (NA). And it looks something like
that:

>dim(red)
  23689  162

>red
        [,1]  [,2]  [,3]  [,4]  [,5]
[1,]    2     NA    4     9     6
[2,]    5     NA    6   NA     1
[3,]   NA    2     11   23    20
[4,]    2      1     21  NA    3
[5,]   NA    7     NA  52    NA

Here I want to convert NA to zero everywhere in the matrix. I do no
want to omit NA using na.omit(red). I want output something like that:
>red
        [,1]  [,2]  [,3]  [,4]  [,5]
[1,]    2      0     4     9     6
[2,]    5      0     6     0     1
[3,]    0      2     11   23    20
[4,]    2      1     21    0     3
[5,]    0      7      0    52     0

Please, help thanks.
Amit




More information about the R-help mailing list