[R] Overlaying the matrices

From: Shubha Vishwanath Karanth <shubhak_at_ambaresearch.com>
Date: Mon, 09 Jun 2008 16:56:48 +0530


Hi R,  

I have a matrix,  

> x1=matrix(NA,6,6,dimnames=list(letters[1:6],LETTERS[1:6]))

> x1

   A B C D E F

a NA NA NA NA NA NA

b NA NA NA NA NA NA

c NA NA NA NA NA NA

d NA NA NA NA NA NA

e NA NA NA NA NA NA

f NA NA NA NA NA NA  

> x2=matrix(rpois(9,1),3,3,dimnames=list(c("b","a","f"),c("D","E","F")))

> x2

  D E F

b 0 3 0

a 2 2 1

f 1 0 0    

I need to put the values of x2 in the corresponding elements of x1. So then, x1 would look like:

   A B C D E F

a NA NA NA 2 2 1

b NA NA NA 0 3 0

c NA NA NA NA NA NA

d NA NA NA NA NA NA

e NA NA NA NA NA NA

f NA NA NA 1 0 0      

What would be the best way to do this?  

Many Thanks,

Shubha    

This e-mail may contain confidential and/or privileged i...{{dropped:13}}



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. Received on Mon 09 Jun 2008 - 11:36:18 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 09 Jun 2008 - 13:30:40 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive