[R] is match slow?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Nov 20 18:35:45 CET 2001
On Tue, 20 Nov 2001, Agustin Lobo wrote:
> I'm doing
> m <- match(matriz, origen, 0)
> where matriz is a 270x900 matrix and
> origen a 11675 elements vector, and is taking
> a very long time.
> Is match a function
> implemented in C? If not, would a C
All of R is implemented in C or Fortran, ultimately. But you could do
function (x, table, nomatch = NA, incomparables = FALSE)
if (!is.logical(incomparables) || incomparables)
.NotYetUsed("incomparables != FALSE")
.Internal(match(if (is.factor(x)) as.character(x) else x,
if (is.factor(table)) as.character(table) else table,
to see that it is a direct call to an internal function, and they
are in C.
> code be faster?
The internal C code (do_match in src/main/unique.c) uses hashing,
so unless that is not doing a good job on your particular data it ought
to be about as fast as possible.
You could have looked at the source code in the same way I did: that's
the beauty of an open-source system.
Brian D. Ripley, ripley at 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 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
More information about the R-help