Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?... Nom : non disponible URL : <https://stat.ethz.ch/pipermail/r-help/attachments/20100224/eca9731e/attachment.pl>
see below. On Wed, Feb 24, 2010 at 12:56 PM, Gustave Lefou <gustave5000 at gmail.com> wrote:> Dear all, > > I do not know how to deal with block matrices in R. > > For example I have 3 matrices A, B and C. > > And I want to produce a new matrix of this form > > ( A B 0 ) > ( 0 0 C ) > > where A, B and C are one-row matrices.cbind(A,B,0) or maybe cbind(a,B,rep(0, 12)) cbind(rep(0,2), C)> > Apart from A, B and C, all the coefficients are 0. > > Is there an easy solution in R for every block matrices ?Combine rbind and cbind: ?rbind Kjetil> > Thanks for your help, > Gustave > > P.S. : I have had a look at a function called "zoo" which looked quite > complicated to me. > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > 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. >
At 1:06 PM -0300 2/24/10, Kjetil Halvorsen wrote:>see below. > >On Wed, Feb 24, 2010 at 12:56 PM, Gustave Lefou <gustave5000 at gmail.com> wrote: >> Dear all, >> >> I do not know how to deal with block matrices in R. >> >> For example I have 3 matrices A, B and C. >> >> And I want to produce a new matrix of this form >> >> ( A B 0 ) >> ( 0 0 C ) >> >> where A, B and C are one-row matrices. > > cbind(A,B,0) or maybe > cbind(a,B,rep(0, 12)) > > cbind(rep(0,2), C)For the case where you have A and B matrices library(psych) C <- super.matrix(A,B) will produce A 0 0 B e.g. A <- matrix(1:4,2,2) B <- matrix(5:16,3,4) C <- super.matrix(A,B) C X1 X2 Y1 Y2 Y3 Y4 Vx1 1 3 0 0 0 0 Vx2 2 4 0 0 0 0 Vy1 0 0 5 8 11 14 Vy2 0 0 6 9 12 15 Vy3 0 0 7 10 13 16 Bill> >> >> Apart from A, B and C, all the coefficients are 0. >> >> Is there an easy solution in R for every block matrices ? > >Combine rbind and cbind: >?rbind > >Kjetil > >> >> Thanks for your help, >> Gustave >> >> P.S. : I have had a look at a function called "zoo" which looked quite >> complicated to me. >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> 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.-- William Revelle http://revelle.net/revelle.html 2815 Lakeside Court http://revelle.net/lakeside Evanston, Illinois It is 6 minutes to midnight http://www.thebulletin.org
On 24/02/2010 10:56 AM, Gustave Lefou wrote:> Dear all, > > I do not know how to deal with block matrices in R. > > For example I have 3 matrices A, B and C. > > And I want to produce a new matrix of this form > > ( A B 0 ) > ( 0 0 C ) > > where A, B and C are one-row matrices. >The problem is that mathematical notation like that assumes a bit of sophistication: each of those 0 matrices is potentially different. So you might need to write a little helper function to build them, e.g. zero <- function(rowMatrix, colMatrix) { matrix(0, nrow = nrow(rowMatrix), ncol=ncol(colMatrix)) } then block <- rbind( cbind(A, B, zero(A, C)), cbind(zero(C, A), zero(C, B), C) ) Duncan Murdoch> Apart from A, B and C, all the coefficients are 0. > > Is there an easy solution in R for every block matrices ? > > Thanks for your help, > Gustave > > P.S. : I have had a look at a function called "zoo" which looked quite > complicated to me. > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >