Re: [R] merging two maxtrices

2010-09-05 Thread Dennis Murphy
j[as.numeric(rownames(k)), ] - k
 j
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [2,]16   11   16   21   26   31   36   4146
 [3,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [4,]27   12   17   22   27   32   37   4247
 [5,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [6,]38   13   18   23   28   33   38   4348
 [7,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [8,]49   14   19   24   29   34   39   4449
 [9,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
[10,]5   10   15   20   25   30   35   40   4550

HTH,
Dennis

On Sun, Sep 5, 2010 at 12:09 AM, steven mosher mosherste...@gmail.comwrote:

  j-matrix(nrow=10,ncol=10)
  k-matrix(seq(1:50), ncol=10)
  row.names(k) - seq(2,10,by=2)
  j
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
  [1,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [2,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [3,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [4,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [5,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [6,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [7,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [8,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [9,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [10,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  k
   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 2 16   11   16   21   26   31   36   4146
 4 27   12   17   22   27   32   37   4247
 6 38   13   18   23   28   33   38   4348
 8 49   14   19   24   29   34   39   4449
 105   10   15   20   25   30   35   40   4550

 is there a simple way to merge j and k By the row.names in k

 so that row named '2' is placed in the 2nd row of j.. and so forth through
 4,6,8,10

 the actual example has a sparse k.. not evenly spaced

 so this should also be mergeable

  row.names(k) - c(1,2,5,6,9)
  k
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 116   11   16   21   26   31   36   4146
 227   12   17   22   27   32   37   4247
 538   13   18   23   28   33   38   4348
 649   14   19   24   29   34   39   4449
 95   10   15   20   25   30   35   40   4550

[[alternative HTML version deleted]]

 __
 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.


[[alternative HTML version deleted]]

__
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] merging two maxtrices

2010-09-05 Thread Bill.Venables
Is this all you want?

 j - matrix(nrow=10,ncol=10)
 k - matrix(seq(1:50), ncol=10)
 row.names(k) - seq(2,10,by=2)
 
 row.names(j) - 1:10
 j[row.names(k), ] - k
 
 j
   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
1NA   NA   NA   NA   NA   NA   NA   NA   NANA
2 16   11   16   21   26   31   36   4146
3NA   NA   NA   NA   NA   NA   NA   NA   NANA
4 27   12   17   22   27   32   37   4247
5NA   NA   NA   NA   NA   NA   NA   NA   NANA
6 38   13   18   23   28   33   38   4348
7NA   NA   NA   NA   NA   NA   NA   NA   NANA
8 49   14   19   24   29   34   39   4449
9NA   NA   NA   NA   NA   NA   NA   NA   NANA
105   10   15   20   25   30   35   40   4550
 

 

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of steven mosher
Sent: Sunday, 5 September 2010 5:10 PM
To: r-help
Subject: [R] merging two maxtrices

  j-matrix(nrow=10,ncol=10)
  k-matrix(seq(1:50), ncol=10)
  row.names(k) - seq(2,10,by=2)
  j
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [2,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [3,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [4,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [5,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [6,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [7,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [8,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [9,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
[10,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  k
   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
2 16   11   16   21   26   31   36   4146
4 27   12   17   22   27   32   37   4247
6 38   13   18   23   28   33   38   4348
8 49   14   19   24   29   34   39   4449
105   10   15   20   25   30   35   40   4550

is there a simple way to merge j and k By the row.names in k

so that row named '2' is placed in the 2nd row of j.. and so forth through
4,6,8,10

the actual example has a sparse k.. not evenly spaced

so this should also be mergeable

 row.names(k) - c(1,2,5,6,9)
 k
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
116   11   16   21   26   31   36   4146
227   12   17   22   27   32   37   4247
538   13   18   23   28   33   38   4348
649   14   19   24   29   34   39   4449
95   10   15   20   25   30   35   40   4550

[[alternative HTML version deleted]]

__
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] merging two maxtrices

2010-09-05 Thread steven mosher
weird, I tried that but it didnt appear to work.. hmm. Thanks I try it again

On Sun, Sep 5, 2010 at 12:21 AM, bill.venab...@csiro.au wrote:

 Is this all you want?

  j - matrix(nrow=10,ncol=10)
  k - matrix(seq(1:50), ncol=10)
  row.names(k) - seq(2,10,by=2)
 
  row.names(j) - 1:10
  j[row.names(k), ] - k
 
  j
   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 1NA   NA   NA   NA   NA   NA   NA   NA   NANA
 2 16   11   16   21   26   31   36   4146
 3NA   NA   NA   NA   NA   NA   NA   NA   NANA
 4 27   12   17   22   27   32   37   4247
 5NA   NA   NA   NA   NA   NA   NA   NA   NANA
 6 38   13   18   23   28   33   38   4348
 7NA   NA   NA   NA   NA   NA   NA   NA   NANA
 8 49   14   19   24   29   34   39   4449
 9NA   NA   NA   NA   NA   NA   NA   NA   NANA
 105   10   15   20   25   30   35   40   4550
 



 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of steven mosher
 Sent: Sunday, 5 September 2010 5:10 PM
 To: r-help
 Subject: [R] merging two maxtrices

  j-matrix(nrow=10,ncol=10)
  k-matrix(seq(1:50), ncol=10)
  row.names(k) - seq(2,10,by=2)
  j
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
  [1,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [2,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [3,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [4,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [5,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [6,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [7,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [8,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [9,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [10,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  k
   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 2 16   11   16   21   26   31   36   4146
 4 27   12   17   22   27   32   37   4247
 6 38   13   18   23   28   33   38   4348
 8 49   14   19   24   29   34   39   4449
 105   10   15   20   25   30   35   40   4550

 is there a simple way to merge j and k By the row.names in k

 so that row named '2' is placed in the 2nd row of j.. and so forth through
 4,6,8,10

 the actual example has a sparse k.. not evenly spaced

 so this should also be mergeable

  row.names(k) - c(1,2,5,6,9)
  k
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 116   11   16   21   26   31   36   4146
 227   12   17   22   27   32   37   4247
 538   13   18   23   28   33   38   4348
 649   14   19   24   29   34   39   4449
 95   10   15   20   25   30   35   40   4550

 [[alternative HTML version deleted]]

 __
 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.


[[alternative HTML version deleted]]

__
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] merging two maxtrices

2010-09-05 Thread steven mosher
ya, unfortunately  k was actually a dataframe and not a matrix when it was
returned
from the function, which explains why I got unexpected results

On Sun, Sep 5, 2010 at 12:21 AM, bill.venab...@csiro.au wrote:

 Is this all you want?

  j - matrix(nrow=10,ncol=10)
  k - matrix(seq(1:50), ncol=10)
  row.names(k) - seq(2,10,by=2)
 
  row.names(j) - 1:10
  j[row.names(k), ] - k
 
  j
   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 1NA   NA   NA   NA   NA   NA   NA   NA   NANA
 2 16   11   16   21   26   31   36   4146
 3NA   NA   NA   NA   NA   NA   NA   NA   NANA
 4 27   12   17   22   27   32   37   4247
 5NA   NA   NA   NA   NA   NA   NA   NA   NANA
 6 38   13   18   23   28   33   38   4348
 7NA   NA   NA   NA   NA   NA   NA   NA   NANA
 8 49   14   19   24   29   34   39   4449
 9NA   NA   NA   NA   NA   NA   NA   NA   NANA
 105   10   15   20   25   30   35   40   4550
 



 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of steven mosher
 Sent: Sunday, 5 September 2010 5:10 PM
 To: r-help
 Subject: [R] merging two maxtrices

  j-matrix(nrow=10,ncol=10)
  k-matrix(seq(1:50), ncol=10)
  row.names(k) - seq(2,10,by=2)
  j
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
  [1,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [2,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [3,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [4,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [5,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [6,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [7,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [8,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [9,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [10,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  k
   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 2 16   11   16   21   26   31   36   4146
 4 27   12   17   22   27   32   37   4247
 6 38   13   18   23   28   33   38   4348
 8 49   14   19   24   29   34   39   4449
 105   10   15   20   25   30   35   40   4550

 is there a simple way to merge j and k By the row.names in k

 so that row named '2' is placed in the 2nd row of j.. and so forth through
 4,6,8,10

 the actual example has a sparse k.. not evenly spaced

 so this should also be mergeable

  row.names(k) - c(1,2,5,6,9)
  k
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 116   11   16   21   26   31   36   4146
 227   12   17   22   27   32   37   4247
 538   13   18   23   28   33   38   4348
 649   14   19   24   29   34   39   4449
 95   10   15   20   25   30   35   40   4550

 [[alternative HTML version deleted]]

 __
 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.


[[alternative HTML version deleted]]

__
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.