[R] Locate first index

Marc Schwartz MSchwartz at medanalytics.com
Fri Sep 19 23:26:12 CEST 2003


On Fri, 2003-09-19 at 15:57, Douglas Bates wrote:
> It may be easier to use the match function which is defined to return
> the index of the first match.
> 
> > corretor <- c(15, 23, 27, 34, 25, 27, 26)
> > match(27, corretor)
> [1] 3


True and presumably much faster as the size of the search vector and the
offset of the first match increases. If this is being done repeatedly,
timing would become important.

Thanks for pointing that out.

Marc




More information about the R-help mailing list