Note: forwarded message attached.

Mistakenly I did not send this to the list!

--- Begin Message ---
Here is a solution which (I think) works, but it
contains a loop which most likely can be eliminated by
more knowledgable people):

Let a and b be like in your example but to make things
more interesting do the following:

rownames(a)[3:4]<-c("b","a")

and now:

a1 <- a[rownames(a) %in% rownames(b),]
b1 <- b[rownames(b) %in% rownames(a),]
c <- unique(rownames(a1))
ia <- numeric(0)
ib <- numeric(0)
for (ronam in c) {
i <- which(rownames(a1) == ronam)
j <- which(rownames(b1) == ronam)
i1 <- rep(i,length(j))
ia <- c(ia,t(matrix(i1,nrow=length(i))))
ib <- c(ib,rep(j,length(i)))
}
result <- cbind(a1[ia,],b1[ib,])


--- Gianni Burgin <[EMAIL PROTECTED]> wrote:

> let say something like this
> 
> 
> >a=matrix(1:25, nrow=5)
> 
> >rownames(a)=letters[1:5]
> > colnames(a)=rep("A", 5)
> 
> > a
>   A  A  A  A  A
> a 1  6 11 16 21
> b 2  7 12 17 22
> c 3  8 13 18 23
> d 4  9 14 19 24
> e 5 10 15 20 25
> 
> > b=matrix(1:40, nrow=8)
> > rownames(b)=c(rep("a",4),rep("b",4))
> > colnames(b)=rep("B", 5)
> 
> > b
>   B  B  B  B  B
> a 1  9 17 25 33
> a 2 10 18 26 34
> a 3 11 19 27 35
> a 4 12 20 28 36
> b 5 13 21 29 37
> b 6 14 22 30 38
> b 7 15 23 31 39
> b 8 16 24 32 40
> 
> as a results I wold like something like
> 
>   A  A  A  A  A  B  B  B  B  B
> a 1  6 11 16 21  1  9 17 25 33
> a 1  6 11 16 21  2 10 18 26 34
> a 1  6 11 16 21  3 11 19 27 35
> a 1  6 11 16 21  4 12 20 28 36
> b 2  7 12 17 22  5 13 21 29 37
> b 2  7 12 17 22  6 14 22 30 38
> b 2  7 12 17 22  7 15 23 31 39
> b 2  7 12 17 22  8 16 24 32 40
> 
> 
> does it is clear? is there a function that automate
> this operation?
> 
> 
> thank you very much!
> 
> 
> 
> 
> On 8/16/07, jim holtman <[EMAIL PROTECTED]> wrote:
> >
> > Can you provide an example of what you mean; e.g.,
> the two input
> > matrices and the desired output.
> >
> > On 8/16/07, Gianni Burgin
> <[EMAIL PROTECTED]> wrote:
> > > Hi R user,
> > >
> > > I am new to R, and I have a very simple question
> for you. I have two
> > matrix
> > > A and B, with internally redundant rownames (but
> variables are
> > different).
> > > Some, but not all the rownames are shared among
> the two matrix. I want
> > to
> > > create a greater matrix that combines the
> previuos two, and has all the
> > > possible combinations of matching rownames lines
> among matrix A and B.
> > >
> > > looking for the solution I bumped in merge but
> actually works on
> > data.frame,
> > > and in dataframe there could be no redundancy in
> names.
> > >
> > >
> > > can you help me??
> > >
> > >        [[alternative HTML version deleted]]
> > >
> > > ______________________________________________
> > > 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
> > > and provide commented, minimal, self-contained,
> reproducible code.
> > >
> >
> >
> > --
> > Jim Holtman
> > Cincinnati, OH
> > +1 513 646 9390
> >
> > What is the problem you are trying to solve?
> >
> 
>       [[alternative HTML version deleted]]
> 
> ______________________________________________
> 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
> and provide commented, minimal, self-contained,
> reproducible code.
> 


--- End Message ---
______________________________________________
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
and provide commented, minimal, self-contained, reproducible code.

Reply via email to