I have a long list of values which I want to use as indexing to remove rows from another data frame which contains this values at a specific column.
A simple examle to make it is
X <- data.frame(Variable1=c(11,14,12,15),Variable2=c(2,3,1,4))
X[X$Variable1!=11 & X$Variable1!=12, ]
We can use
%in% for creating a logical index based on multiple values.
X[!(X$Variable1 %in% c(11, 12)),]
If we are using
data.table an option would be to
key and then negate the values
library(data.table) setDT(X, key = "Variable1")[!.(c(11,12))] # Variable1 Variable2 #1: 14 3 #2: 15 4
Or we use
on as @David Arenburg commented
setDT(X)[!.(11:12), on = "Variable1"]