[R] comparing two matrices

Adrian Dusa dusa.adrian at gmail.com
Sun Jan 21 11:17:13 CET 2007


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



More information about the R-help mailing list