Re: [R] comparing two matrices

From: <Bill.Venables_at_csiro.au>
Date: Sun 21 Jan 2007 - 22:44:06 GMT

But this is using paste() the wrong way round. A better way would be

> join <- function(x) do.call("paste", c(as.data.frame(x), sep = "\r"))
> which(join(mat1) %in% join(mat2))

[1] 8 13 16 19 24

This is essentially the technique used by duplicated.data.frame

Bill Venables

-----Original Message-----
From: r-help-bounces@stat.math.ethz.ch
[mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Adrian Dusa Sent: Sunday, 21 January 2007 8:17 PM
To: Dimitris Rizopoulos
Cc: marc_schwartz@comcast.net; r-help@stat.math.ethz.ch Subject: Re: [R] comparing two matrices

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, collapse = "/")
> match(ind2, ind1)

Oh yes, I thought about that too.
It works fast enough for small matrices, but I deal with very large ones.
Using paste() on such matrices decreases the speed dramatically.

Thanks again,
Adrian

-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
          +40 21 3120210 / int.101

______________________________________________
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.

______________________________________________
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.
Received on Mon Jan 22 09:49:58 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 21 Jan 2007 - 23:30:34 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.