Re: [R] is match slow?

About this list Date view Thread view Subject view Author view Attachment view

From: Prof Brian Ripley (ripley@stats.ox.ac.uk)
Date: Wed 21 Nov 2001 - 04:35:45 EST


Message-id: <Pine.LNX.4.31.0111201727450.12894-100000@gannet.stats>

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
> match
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,
        nomatch))
}
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@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@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Thu 17 Jan 2002 - 11:10:09 EST