Re: [R] comparing two matrices, row by row

2007-04-26 Thread Finny Kuruvilla
Another similar way to do this using apply is: apply(ar1==ar2,1,all) Best, Finny Kuruvilla * Finny Kuruvilla, MD, PhD Harvard Medical School Fellowship Program in Transfusion Medicine Broad Institute of MIT and Harvard Homepage: htt

[R] comparing two matrices, row by row

2007-04-26 Thread Federico Abascal
Estimated people, I have two matrices: ar1 <- array(data=c(1:16),dim=c(4,4)) ar2 <- array(data=c(1,2,3,3,5:16),dim=c(4,4)) They only differ in the fourth row. I would like to compare them in order to know which columns are equal. The following works, but I would like to have a better

Re: [R] comparing two matrices, row by row

2007-04-26 Thread gyadav
HTH Federico Abascal <[EMAIL PROTECTED]> Sent by: [EMAIL PROTECTED] 26-04-07 04:14 PM To r-help@stat.math.ethz.ch cc Subject [R] comparing two matrices, row by row Estimated people, I have two matrices: ar1 <- array(data=c(1:16),dim=c(4,4)) ar2 <- array(data=c(1,2,3,3,5:16),di

[R] comparing two matrices, row by row

2007-04-26 Thread Federico Abascal
Estimated people, I have two matrices: ar1 <- array(data=c(1:16),dim=c(4,4)) ar2 <- array(data=c(1,2,3,3,5:16),dim=c(4,4)) They only differ in the fourth row. I would like to compare them in order to know which columns are equal. The following works, but I would like to have a better solution,

Re: [R] comparing two matrices

2007-01-21 Thread Bill.Venables
Bill Venables -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Adrian Dusa Sent: Sunday, 21 January 2007 8:17 PM To: Dimitris Rizopoulos Cc: [EMAIL PROTECTED]; r-help@stat.math.ethz.ch Subject: Re: [R] comparing two matrices On Sunday 21 January 2007 12:04, D

Re: [R] comparing two matrices

2007-01-21 Thread Adrian Dusa
On Sunday 21 January 2007 12:04, Dimitris Rizopoulos wrote: > I think the following should work in your case: > > mat1 <- data.matrix(expand.grid(0:2, 0:2, 0:2)) > mat2 <- mat1[c(19, 16, 13, 24, 8), ] > > ind1 <- apply(mat1, 1, paste, collapse = "/") > ind2 <- apply(mat2, 1, paste, col

Re: [R] comparing two matrices

2007-01-21 Thread Dimitris Rizopoulos
I think the following should work in your case: mat1 <- data.matrix(expand.grid(0:2, 0:2, 0:2)) mat2 <- mat1[c(19, 16, 13, 24, 8), ] ind1 <- apply(mat1, 1, paste, collapse = "/") ind2 <- apply(mat2, 1, paste, collapse = "/") match(ind2, ind1) I hope it helps. Best, Dimitris Quoti

Re: [R] comparing two matrices

2007-01-21 Thread Adrian Dusa
Hello Marc and Dimitris, There was an error in my first example (therefore not reproducible), so mat1 <- expand.grid(0:2, 0:2, 0:2) mat2 <- mat1[c(19, 16, 13, 24, 8), ] Your solution works if and only if the elements in both matrices are unique. Unfortunately, it does not apply for my matrices w

Re: [R] comparing two matrices

2007-01-21 Thread Adrian Dusa
Hi Christos, It's... more or less the same thing. I was looking for a matrix.to.matrix.run.me() function :) Cheers, Adrian On Sunday 21 January 2007 00:56, Christos Hatzis wrote: > Here is a slightly more compact version of your function which might run > faster (I did not test timings) since i

Re: [R] comparing two matrices

2007-01-21 Thread Dimitris Rizopoulos
based on Marc's approach, I think you can even use which((mat2 %in% mat1)[1:nrow(mat2)]) instead of which(apply(matrix(mat2 %in% mat1, dim(mat2)), 1, all)) I hope it helps. Best, Dimitris Quoting Marc Schwartz <[EMAIL PROTECTED]>: > On Sun, 2007-01-21 at 00:14 +0200, Adrian Dusa wrote: >>

Re: [R] comparing two matrices

2007-01-20 Thread Marc Schwartz
On Sun, 2007-01-21 at 00:14 +0200, Adrian Dusa wrote: > Dear helpeRs, > > I have two matrices: > mat1 <- expand.grid(0:2, 0:2, 0:2) > mat2 <- aa[c(19, 16, 13, 24, 8), ] > > where mat2 is always a subset of mat1 > > I need to find the corersponding row numbers in mat1 for each row in mat2. > For

Re: [R] comparing two matrices

2007-01-20 Thread Christos Hatzis
PROTECTED] On Behalf Of Adrian Dusa Sent: Saturday, January 20, 2007 5:15 PM To: r-help@stat.math.ethz.ch Subject: [R] comparing two matrices Dear helpeRs, I have two matrices: mat1 <- expand.grid(0:2, 0:2, 0:2) mat2 <- aa[c(19, 16, 13, 24, 8), ] where mat2 is always a subset of mat1 I n

[R] comparing two matrices

2007-01-20 Thread Adrian Dusa
Dear helpeRs, I have two matrices: mat1 <- expand.grid(0:2, 0:2, 0:2) mat2 <- aa[c(19, 16, 13, 24, 8), ] where mat2 is always a subset of mat1 I need to find the corersponding row numbers in mat1 for each row in mat2. For this I have the following code: apply(mat2, 1, function(x) { which(a

Re: [R] Comparing two matrices [Broadcast]

2006-07-28 Thread Srinivas Iyyer
Hi Andy, Thank you very much for your previous tip. However, I am running into another problem now. previously, in my tab-delim file I had only two columns. now I added another column. and I want the pairs value to go into the matrix instead of 1. pair (Apple, S) value 10. > > > tb # t

Re: [R] Comparing two matrices

2006-07-06 Thread Duncan Murdoch
On 7/6/2006 8:18 AM, Srinivas Iyyer wrote: > hi: > > I have matrix with dimensions(200 X 20,000). I have > another file, a tab-delim file where first column > variables are row names and second column variables > are column names. > > > For instance: > >> tmat > Apple Orange Mango Grape Star

Re: [R] Comparing two matrices

2006-07-06 Thread Dimitris Rizopoulos
l Message - From: "Srinivas Iyyer" <[EMAIL PROTECTED]> To: Sent: Thursday, July 06, 2006 2:18 PM Subject: [R] Comparing two matrices > hi: > > I have matrix with dimensions(200 X 20,000). I have > another file, a tab-delim file where first column > variables are row

Re: [R] Comparing two matrices

2006-07-06 Thread Peter Dalgaard
Srinivas Iyyer <[EMAIL PROTECTED]> writes: > hi: > > I have matrix with dimensions(200 X 20,000). I have > another file, a tab-delim file where first column > variables are row names and second column variables > are column names. > > > For instance: > > > tmat > Apple Orange Mango Grape St

Re: [R] Comparing two matrices [Broadcast]

2006-07-06 Thread Liaw, Andy
It might be a bit faster to do matrix indexing: R> tbm <- as.matrix(tb) # turn it into a character matrix R> tmat[cbind(match(tbm[,2], rownames(tmat)), match(tbm[,1], colnames(tmat)))] <- 1 > tmat Apple Orange Mango Grape Star A 1 1 1 00 O 1 1 0 00 M

[R] Comparing two matrices

2006-07-06 Thread Srinivas Iyyer
hi: I have matrix with dimensions(200 X 20,000). I have another file, a tab-delim file where first column variables are row names and second column variables are column names. For instance: > tmat Apple Orange Mango Grape Star A 0 0 0 00 O 0 0 0 00 M