Filtering on a large list of values

I am trying to do something like this:

df1 <- df1 %>% filter(var %in% list)

The issue is my list that I need to filter on is around 15000 elements long, and the error I am getting seems to say that filter %in% can only handle up to 1000 elements.

I've conceptualized a for loop to run through my elements using filter, but I am wondering if there is another way to do this?

Have you tried a semi_join()?

library(dplyr)
FilterDF <- data.frame(var = list)
df1 <- semi_join(df1, FilterDF, by = "var")
1 Like
set.seed(42)
targets <- rnorm(15000)
targets[7500] <- 1
d <- data.frame(
    bow = 0,
    arrow = 1)
has_hit <- function(x) x %in% targets
apply(d,2,has_hit)
#>   bow arrow 
#> FALSE  TRUE

Created on 2023-10-12 with reprex v2.0.2

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.