[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
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 at 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
>
>
More information about the R-help
mailing list