Re: [R] removing missing values from a matrix

2009-10-02 Thread Amit Kumar
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@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@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.


Re: [R] removing missing values from a matrix

2009-10-02 Thread jim holtman
Here is one way to do it.  BTW 'a'-'z' won't work because there are 41
splits.  Use a list instead:

 red - matrix(seq(23688 * 164), nrow=23688, ncol=164)
 # create indices
 indx - split(1:164, cut(1:164, 41))
 # now split matrix
 newMatrix - lapply(indx, function(x) red[, x])

 str(newMatrix)
List of 41
 $ (0.837,4.82]: int [1:23688, 1:4] 1 2 3 4 5 6 7 8 9 10 ...
 $ (4.82,8.8]  : int [1:23688, 1:4] 94753 94754 94755 94756 94757
94758 94759 94760 94761 94762 ...
 $ (8.8,12.8]  : int [1:23688, 1:4] 189505 189506 189507 189508 189509
189510 189511 189512 189513 189514 ...
 $ (12.8,16.8] : int [1:23688, 1:4] 284257 284258 284259 284260 284261
284262 284263 284264 284265 284266 ...
 $ (16.8,20.8] : int [1:23688, 1:4] 379009 379010 379011 379012 379013
379014 379015 379016 379017 379018 ...
 $ (20.8,24.7] : int [1:23688, 1:4] 473761 473762 473763 473764 473765
473766 473767 473768 473769 473770 ...
 $ (24.7,28.7] : int [1:23688, 1:4] 568513 568514 568515 568516 568517
568518 568519 568520 568521 568522 ...
 $ (28.7,32.7] : int [1:23688, 1:4] 663265 663266 663267 663268 663269
663270 663271 663272 663273 663274 ...
 $ (32.7,36.7] : int [1:23688, 1:4] 758017 758018 758019 758020 758021
758022 758023 758024 758025 758026 ...
 $ (36.7,40.7] : int [1:23688, 1:4] 852769 852770 852771 852772 852773
852774 852775 852776 852777 852778 ...
 $ (40.7,44.7] : int [1:23688, 1:4] 947521 947522 947523 947524 947525
947526 947527 947528 947529 947530 ...


On Thu, Oct 1, 2009 at 6:57 PM, Amit Kumar amitkumartiw...@gmail.com wrote:
 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@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@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.




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
R-help@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.


Re: [R] removing missing values from a matrix

2009-10-02 Thread Amit Kumar
Thanks! Jim
It solved my problem.

Best
Amit

On Fri, Oct 2, 2009 at 11:19 AM, jim holtman jholt...@gmail.com wrote:
 Here is one way to do it.  BTW 'a'-'z' won't work because there are 41
 splits.  Use a list instead:

 red - matrix(seq(23688 * 164), nrow=23688, ncol=164)
 # create indices
 indx - split(1:164, cut(1:164, 41))
 # now split matrix
 newMatrix - lapply(indx, function(x) red[, x])

 str(newMatrix)
 List of 41
  $ (0.837,4.82]: int [1:23688, 1:4] 1 2 3 4 5 6 7 8 9 10 ...
  $ (4.82,8.8]  : int [1:23688, 1:4] 94753 94754 94755 94756 94757
 94758 94759 94760 94761 94762 ...
  $ (8.8,12.8]  : int [1:23688, 1:4] 189505 189506 189507 189508 189509
 189510 189511 189512 189513 189514 ...
  $ (12.8,16.8] : int [1:23688, 1:4] 284257 284258 284259 284260 284261
 284262 284263 284264 284265 284266 ...
  $ (16.8,20.8] : int [1:23688, 1:4] 379009 379010 379011 379012 379013
 379014 379015 379016 379017 379018 ...
  $ (20.8,24.7] : int [1:23688, 1:4] 473761 473762 473763 473764 473765
 473766 473767 473768 473769 473770 ...
  $ (24.7,28.7] : int [1:23688, 1:4] 568513 568514 568515 568516 568517
 568518 568519 568520 568521 568522 ...
  $ (28.7,32.7] : int [1:23688, 1:4] 663265 663266 663267 663268 663269
 663270 663271 663272 663273 663274 ...
  $ (32.7,36.7] : int [1:23688, 1:4] 758017 758018 758019 758020 758021
 758022 758023 758024 758025 758026 ...
  $ (36.7,40.7] : int [1:23688, 1:4] 852769 852770 852771 852772 852773
 852774 852775 852776 852777 852778 ...
  $ (40.7,44.7] : int [1:23688, 1:4] 947521 947522 947523 947524 947525
 947526 947527 947528 947529 947530 ...


 On Thu, Oct 1, 2009 at 6:57 PM, Amit Kumar amitkumartiw...@gmail.com wrote:
 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@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@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.




 --
 Jim Holtman
 Cincinnati, OH
 +1 513 646 9390

 What is the problem that you are trying to solve?


__
R-help@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.


Re: [R] removing missing values from a matrix

2009-10-01 Thread Carvalho, Benilton
red[is.na(red)] - 0

Sent from my iPhone

On Oct 1, 2009, at 7:22 PM, Amit Kumar amitkumartiw...@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 NA4 9 6
 [2,]5 NA6   NA 1
 [3,]   NA2 11   2320
 [4,]2  1 21  NA3
 [5,]   NA7 NA  52NA

 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   2320
 [4,]2  1 210 3
 [5,]0  7  052 0

 Please, help thanks.
 Amit

 __
 R-help@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@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.


Re: [R] removing missing values from a matrix

2009-10-01 Thread Bert Gunter
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-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Carvalho, Benilton
Sent: Thursday, October 01, 2009 3:34 PM
To: Amit Kumar
Cc: r-help@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 amitkumartiw...@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 NA4 9 6
 [2,]5 NA6   NA 1
 [3,]   NA2 11   2320
 [4,]2  1 21  NA3
 [5,]   NA7 NA  52NA

 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   2320
 [4,]2  1 210 3
 [5,]0  7  052 0

 Please, help thanks.
 Amit

 __
 R-help@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@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@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.


Re: [R] removing missing values from a matrix

2009-10-01 Thread Rolf Turner


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 idea


I heartily second that hazard!!!

cheers,

Rolf Turner


Bert Gunter
Genentech Nonclinical Biostatistics



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- 
project.org] On

Behalf Of Carvalho, Benilton
Sent: Thursday, October 01, 2009 3:34 PM
To: Amit Kumar
Cc: r-help@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 amitkumartiw...@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 NA4 9 6
[2,]5 NA6   NA 1
[3,]   NA2 11   2320
[4,]2  1 21  NA3
[5,]   NA7 NA  52NA

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   2320
[4,]2  1 210 3
[5,]0  7  052 0

Please, help thanks.
Amit

__
R-help@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@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@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}}

__
R-help@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.


Re: [R] removing missing values from a matrix

2009-10-01 Thread Carvalho, Benilton
I agree with you folks, my assumption is that the user knows what he's
doing.


Sent from my iPhone

On Oct 1, 2009, at 8:33 PM, Rolf Turner r.tur...@auckland.ac.nz
wrote:


 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 idea

I heartily second that hazard!!!

cheers,

Rolf Turner

 Bert Gunter
 Genentech Nonclinical Biostatistics



 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On
 Behalf Of Carvalho, Benilton
 Sent: Thursday, October 01, 2009 3:34 PM
 To: Amit Kumar
 Cc: r-help@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 amitkumartiw...@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 NA4 9 6
 [2,]5 NA6   NA 1
 [3,]   NA2 11   2320
 [4,]2  1 21  NA3
 [5,]   NA7 NA  52NA

 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   2320
 [4,]2  1 210 3
 [5,]0  7  052 0

 Please, help thanks.
 Amit

 __
 R-help@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@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@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 confidential. If you are not the
 intended recipient please delete the message and notify the sender.
 Any views or opinions presented are solely those of the author.

 This e-mail has been scanned and cleared by MailMarshal
 www.marshalsoftware.com
 ##

__
R-help@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.


Re: [R] removing missing values from a matrix

2009-10-01 Thread Rolf Turner


On 2/10/2009, at 1:03 PM, Carvalho, Benilton wrote:


I agree with you folks, my assumption is that the user knows what he's
doing.


Almost surely a rash assumption! (I.e. except for a set of
users of probability zero.) :-)

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
R-help@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.