John Fox, Professor
McMaster University
Hamilton, Ontario, Canada
http://socserv.socsci.mcmaster.ca/jfox/
-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
ller
> 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 for the reproducible example, but posting in HTML can corrupt
> your example code so please learn to s
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 solu
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.
m
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 wrote:
> Dear Charles,
>
> How about the following?
>
> --- snip -
>
> > AA <- as.list(as.data.frame(t(A)))
> > BB <- as.list(as.data.frame(t(B
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,
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 th
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. Somethin
Also look at
?any
and
?all
Very handy functions.
Miguel
On Thu, Mar 11, 2010 at 12:37 PM, Esmail 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 this operation.
>
Behalf 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'
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 { cat(
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
David Winsemius wrote:
> 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
Thanks David, much appreciated.
Esmail
__
R-help@r-project.org mailing list
https://s
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 Babtiste
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
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 wro
le answer can 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
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
[4,]
you just need pmax() or pmin(), e.g., check this:
set.seed(123)
M1 <- matrix(rnorm(20), 4, 5)
M2 <- matrix(rnorm(20), 4, 5)
M3 <- matrix(rnorm(20), 4, 5)
M1; M2; M3
pmax(M1, M2, M3)
pmin(M1, M2, M3)
I hope it helps.
Best,
Dimitris
Diogo André Alagador wrote:
Dear all,
I have 3 matrices w
#how about this
A <- rnorm(10)
B <- rnorm(10)
C <- rnorm(10)
D <- data.frame(A,B,C)
apply(D, MARGIN=1, FUN=min)
On Thu, Nov 6, 2008 at 10:00 AM, Diogo André Alagador
<[EMAIL PROTECTED]> wrote:
> Dear all,
>
> I have 3 matrices with the same dimension, A,B,C and I would like to produce
> a matrix
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 i
21 matches
Mail list logo