Here is one way of doing it:
>compMat2 <- function(A, B) { # rows of B present in A
+B0 <- B[!duplicated(B), ]
+na <- nrow(A); nb <- nrow(B0)
+AB <- rbind(A, B0)
+ab <- duplicated(AB)[(na+1):(na+nb)]
+return(sum(ab))
+}
>
>
>set.seed(8237)
>
Michael Kao gmail.com> writes:
>
Well, taking a second look, I'd say it depends on the exact formulation.
In the applications I have in mind, I would like to count each occurrence
in B only once. Perhaps the OP never thought about duplicates in B
Hans Werner
>
> Here is an example based on t
Michael Kao gmail.com> writes:
>
Your solution is fast, but not completely correct, because you are also
counting possible duplicates within the second matrix. The 'refitted'
function could look as follows:
compMat2 <- function(A, B) { # rows of B present in A
B0 <- B[!duplicated(
On 2/12/2011 2:48 p.m., David Winsemius wrote:
On Dec 2, 2011, at 4:20 AM, oluwole oyebamiji wrote:
Hi all,
I have matrix A of 67420 by 2 and another matrix B of 59199 by 2.
I would like to find the number of rows of matrix B that I can find
in matrix A (rows that are common to both matr
On Dec 2, 2011, at 4:20 AM, oluwole oyebamiji wrote:
Hi all,
I have matrix A of 67420 by 2 and another matrix B of 59199 by
2. I would like to find the number of rows of matrix B that I can
find in matrix A (rows that are common to both matrices with or
without sorting).
I have trie
Hi all,
I have matrix A of 67420 by 2 and another matrix B of 59199 by 2. I would
like to find the number of rows of matrix B that I can find in matrix A (rows
that are common to both matrices with or without sorting).
I have tried the "intersection" and "is.element" functions in R but it on
6 matches
Mail list logo