[R] counting the occurrences of vectors

Spencer Graves spencer.graves at pdf.com
Sat Jul 3 17:27:43 CEST 2004

      What have you tried?  Have you considered something like the 

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:

>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.
>	[[alternative HTML version deleted]]
>R-help at stat.math.ethz.ch mailing list
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

More information about the R-help mailing list