Re: [R] Vector comparison to matrix

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Mon 15 Aug 2005 - 17:33:50 EST

On Mon, 15 Aug 2005, Prof Brian Ripley wrote:

> Probably you use the idea from unique.matrix, that is
>
> 1) form a string from each row and
> 2) call match() to see which strings match your pattern row.

If your matrix A really does have short rows like c(1,2,3) and millions of them, another idea is to do

target <- rep(c(1,2,3), each= nrow(A))
rowSums(A != target) == 0

For wider rows my first suggestion is probably faster.

> On Sun, 14 Aug 2005, Todd Remund wrote:
>
>> I am looking for a fast way to count the number of rows in a matrix are
>> identical to a pattern vector. For example, if I am interested in counting
>> the number of row vectors in a matrix that are identical to (1,2,3) what
>> would I do? I have tried the identical statement in a loop but this is far
>> too slow. I have a very large matrix and need to avoid loops at all costs.

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Mon Aug 15 17:39:53 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 15:19:48 EST