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
red[is.na(red)] <- 0 Sent from my iPhone On Oct 1, 2009, at 7:22 PM, "Amit Kumar" <amitkumartiwary at gmail.com> wrote:> 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 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Thanks! It worked! There is another problem I want to subset the matrix 'red' in following manner:>dim(red)23688 164>a=red[1:23688,1:4] >b=red[1:23688,5:8] >c=red[1:23688,9:12].............................. ..............................>z=red[1:23688,161:164]If there any efficient way to do it? cheers! Amit> > On Thu, 1 Oct 2009, Amit Kumar wrote: > >> 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 >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >
However, I would hazard the guess that doing this is a (possibly disastrously) bad idea. Bert Gunter Genentech Nonclinical Biostatistics -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Carvalho, Benilton Sent: Thursday, October 01, 2009 3:34 PM To: Amit Kumar Cc: r-help at r-project.org Subject: Re: [R] removing missing values from a matrix red[is.na(red)] <- 0 Sent from my iPhone On Oct 1, 2009, at 7:22 PM, "Amit Kumar" <amitkumartiwary at gmail.com> wrote:> 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 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
On 2/10/2009, at 12:05 PM, Bert Gunter wrote:> However, I would hazard the guess that doing this is a (possibly > disastrously) bad ideaI heartily second that hazard!!! cheers, Rolf Turner> Bert Gunter > Genentech Nonclinical Biostatistics > > > > -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On > Behalf Of Carvalho, Benilton > Sent: Thursday, October 01, 2009 3:34 PM > To: Amit Kumar > Cc: r-help at r-project.org > Subject: Re: [R] removing missing values from a matrix > > red[is.na(red)] <- 0 > > Sent from my iPhone > > On Oct 1, 2009, at 7:22 PM, "Amit Kumar" <amitkumartiwary at gmail.com> > wrote: > >> 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 >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code.###################################################################### Attention:\ This e-mail message is privileged and confid...{{dropped:9}}