Re: [R] Combining two matrices

From: Pedro de Barros <pbarros_at_ualg.pt>
Date: Thu 21 Jul 2005 - 03:42:19 EST

Hi,

Se if this will solve your question (quick and dirty)... A is the first matrix, B is the second...

"F.CombineMat" <-
function (A, B)
{
ind<-rep(1:nrow(A),ceiling(nrow(B)/nrow(A))) ind<-ind[1:nrow(B)]
A<-A[ind,]
colnames(A)<-paste('A', colnames(A), sep='') R<-cbind(A,B)
R
}
Greetings,
Pedro

At 18:24 20/07/2005, you wrote:
>The latter, I want to replicate A enough times to have the same rows
>as B. I realize that 16063 is not a mutliple 217, that doesn't really
>matter for this problem
>Assuming I change the colnames of one of them, how can I create a
>matrix C that is the composite of the replicated A with B.
>
>thank you again.
>
>On 7/20/05, Pedro de Barros <pbarros@ualg.pt> wrote:
> > Please clarify:
> > Is there a column of common values that you want to use to merge the two
> > matrices together? Or do you just want to replicate matrix A enough times
> > to have the same number of rows as B? I could think this was the case, but
> > 16063 is not a multiple of 217.
> > Anyway, you will have to change the colnames of at least one of them.
> >
> > Pedro
> > At 18:03 20/07/2005, you wrote:
> > >Can someone please refer me to a function or method that resolves this
> > >structuring issue:
> > >
> > >I have two matrices with identical colnames (89), but varying number
> > >of observations:
> > >
> > >matrix A matrix B
> > >
> > >217 x 89 16063 x 89
> > >
> > >I want to creat one matrix C that has both matrices adjacent to one
> > >another, where matrix A is duplicated many times to create the same
> > >row number for matrix B, i.e. 16063.
> > >
> > >matrixA matrix B
> > >matrixA
> > >matrixA
> > >
> > >so matrix C will be 16063 x 178
> > >
> > >I've tried cbind() and merge() with no success..
> > >
> > >______________________________________________
> > >R-help@stat.math.ethz.ch mailing list
> > >https://stat.ethz.ch/mailman/listinfo/r-help
> > >PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
> >
> >



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jul 21 03:45:47 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:53 EST