The fastmatch package implements a much faster version of match
for repeated matches (e.g. in a loop):
set.seed(1)
library(fastmatch)
table <- 1L:100000L
x <- sample(table, 10000, replace=TRUE)
system.time(for(i in 1:100) a <- match(x, table))
system.time(for(i in 1:100) b <- fmatch(x, table))
identical(a, b)
Is there a similar implementation for %in%
I could use to speed up repeated lookups?
match is almost always better done by putting both vectors in dataframes and merging (see various joins from dplyr)
For example, something like this would give you all the info you need:
or left_join, right_join, full_join, semi_join, anti_join, depending on what info is most useful to you
Look at the definition of
%in%
:It's easy to write your own
%fin%
function: