Re: [R] counting the occurrences of vectors

From: Spencer Graves <spencer.graves_at_pdf.com>
Date: Sun 04 Jul 2004 - 01:27:43 EST

      What have you tried? Have you considered something like the following:

n <- 4
m <- 3
k <- 2
A <- array(1, dim=c(n, k))
B <- array(1, dim=c(m,k))

BinA <- rep(NA, m)
tA <- t(A)
for(i in 1:m){
  BinA[i] <- sum(apply(B[i,]==tA, 2, sum)==k) }  

 > BinA
[1] 4 4 4

      hope this helps. spencer graves

Ravi Varadhan wrote:

>Hi:
>
>I have two matrices, A and B, where A is n x k, and B is m x k, where n >> m >> k. Is there a computationally fast way to count the number of times each row (a k-vector) of B occurs in A? Thanks for any suggestions.
>
>Best,
>Ravi.
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>R-help@stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>



R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sun Jul 04 01:30:30 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:54:40 EST