[R] Comparing matrices in R - matrixB %in% matrixA

2014-10-31 Thread Charles Novaes de Santana
A = matrix(1:10,nrow=5) B = A[-c(1,2,3),]; So A [,1] [,2] [1,]16 [2,]27 [3,]38 [4,]49 [5,]5 10 and B [,1] [,2] [1,]49 [2,]5 10 I would like to compare A and B in order to find in which rows of A I can find the rows of B. Something

Re: [R] Comparing matrices in R - matrixB %in% matrixA

2014-10-31 Thread Charles Novaes de Santana
My apologies, because I sent the message before finishing it. i am very sorry about this. Please find below my message (I use to write the messages from the end to the beginning... sorry :)). Dear all, I am trying to compare two matrices, in order to find in which rows of a matrix A I can find

Re: [R] Comparing matrices in R - matrixB %in% matrixA

2014-10-31 Thread John Fox
Dear Charles, How about the following? --- snip - AA - as.list(as.data.frame(t(A))) BB - as.list(as.data.frame(t(B))) which(AA %in% BB) [1] 4 5 --- snip - This seems reasonably fast. For example: --- snip - A - matrix(1:1, 1, 10)

Re: [R] Comparing matrices in R - matrixB %in% matrixA

2014-10-31 Thread Charles Novaes de Santana
Great!! It is perfect! Thank you, John, for this elegant and fast suggestion! Best, Charles On Fri, Oct 31, 2014 at 2:35 PM, John Fox j...@mcmaster.ca wrote: Dear Charles, How about the following? --- snip - AA - as.list(as.data.frame(t(A))) BB -

Re: [R] Comparing matrices in R - matrixB %in% matrixA

2014-10-31 Thread Jeff Newmiller
Thank you for the reproducible example, but posting in HTML can corrupt your example code so please learn to set your email client mail format appropriately when posting to this list. I think this [1] post, found with a quick Google search for R match matrix, fits your situation perfectly.

Re: [R] Comparing matrices in R - matrixB %in% matrixA

2014-10-31 Thread Charles Novaes de Santana
Thank you, Jeff, for your message. I did a search, but maybe my problem was that I didn't know the correct way to search my problem (in other words: my vocabulary in R/English is not good). Because of this I choose to send a message to the list the most detailed as possible, and with a first

Re: [R] Comparing matrices in R - matrixB %in% matrixA

2014-10-31 Thread John Fox
-project.org Subject: Re: [R] Comparing matrices in R - matrixB %in% matrixA Thank you for the reproducible example, but posting in HTML can corrupt your example code so please learn to set your email client mail format appropriately when posting to this list. I think this [1] post, found

Re: [R] Comparing matrices in R - matrixB %in% matrixA

2014-10-31 Thread Jeff Newmiller
/ -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Jeff Newmiller Sent: Friday, October 31, 2014 10:15 AM To: Charles Novaes de Santana; r-help@r-project.org Subject: Re: [R] Comparing matrices in R - matrixB %in% matrixA Thank you

[R] Comparing matrices

2010-03-11 Thread Esmail
Hello all, I have two matrices, pop and pop2, each the same number of rows and columns that I want to compare for equality. I am concerned about efficiency in this operation. I've tried a few things without success so far. Doing something simple like: if (pop==pop2) { cat('equal') } else {

Re: [R] Comparing matrices

2010-03-11 Thread Ravi Varadhan
Of Esmail Sent: Thursday, March 11, 2010 7:38 AM To: r-help@r-project.org Subject: [R] Comparing matrices Hello all, I have two matrices, pop and pop2, each the same number of rows and columns that I want to compare for equality. I am concerned about efficiency in this operation. I've tried a few

Re: [R] Comparing matrices

2010-03-11 Thread Miguel Porto
Also look at ?any and ?all Very handy functions. Miguel On Thu, Mar 11, 2010 at 12:37 PM, Esmail esmail...@gmail.com wrote: Hello all, I have two matrices, pop and pop2, each the same number of rows and columns that I want to compare for equality. I am concerned about efficiency in

[R] comparing matrices

2009-04-26 Thread Esmail
I'm trying to compare two matrices made up of bits. doing a simple comparison of matA == matB yields this sort of output. [,1] [,2] [,3] [,4] [,5] [,6] [1,] FALSE TRUE FALSE TRUE TRUE FALSE [2,] TRUE TRUE TRUE TRUE TRUE TRUE [3,] FALSE TRUE FALSE FALSE FALSE TRUE

Re: [R] comparing matrices

2009-04-26 Thread ONKELINX, Thierry
be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Esmail Verzonden: zondag 26 april 2009 19:03 Aan: R mailing list Onderwerp: [R] comparing matrices I'm trying to compare two

Re: [R] comparing matrices

2009-04-26 Thread baptiste auguie
I'm not sure I'm following you but have you tried, identical(matrix(c(1,1,1,1),ncol=2), matrix(c(1,1,1,1),ncol=2)) ?all.equal ?isTRUE ?identical and possibly the compare package, compare(matrix(c(1,1,1,1),ncol=2),matrix(c(1,1,1,1),ncol=2)) HTH, baptiste On 26 Apr 2009, at 18:02, Esmail

Re: [R] comparing matrices

2009-04-26 Thread David Winsemius
On Apr 26, 2009, at 1:02 PM, Esmail wrote: I'm trying to compare two matrices made up of bits. doing a simple comparison of matA == matB identical( matrix((1:4), ncol=2), matrix((1:4), nrow=2)) [1] TRUE identical( matrix((1:4), ncol=2), matrix((2:5), nrow=2)) [1] FALSE yields

Re: [R] comparing matrices

2009-04-26 Thread Esmail
baptiste auguie wrote: I'm not sure I'm following you but have you tried, identical(matrix(c(1,1,1,1),ncol=2), matrix(c(1,1,1,1),ncol=2)) ?all.equal ?isTRUE ?identical and possibly the compare package, compare(matrix(c(1,1,1,1),ncol=2),matrix(c(1,1,1,1),ncol=2)) HTH, baptiste Hi

Re: [R] comparing matrices

2009-04-26 Thread Esmail
ONKELINX, Thierry wrote: Have a look at all.equal matA - matrix(1:4, ncol = 2) matB - matA all.equal(matA, matB) matB[1,1] - -10 all.equal(matA, matB) Hi Thierry, Thanks, all.equal does indicate if it's all equal so that works great! Much nicer than my hack - thanks, Esmail

[R] comparing matrices using max or min

2008-11-06 Thread Diogo André Alagador
Dear all, I have 3 matrices with the same dimension, A,B,C and I would like to produce a matrix D where in each position would retrieve the max(or min) value along A,B,C taken from the same position. I guess that apply functions should fit, but for matrices objects I am not getting it. thanks