Skip to content
Prev 5797 / 29559 Next

How to negate %in%

Hi All,

Everyone's suggestions work. There are lots
of roads to solutions in R. This is wonderful!

It seems that Dan's and Pedro's solutions
work faster for my largish 1,897 spatial
polygon data frame.

Thanks,
Jim Burke

All replies are below.

=================================================
Hi This (!) might work:
aa <- 1:10
bb <- 5:6
aa[!aa %in% bb]     ## Yes it works
[1]  1  2  3  4  7  8  9 10
aa[aa %in% bb]
[1] 5 6
Best wishes
Torleif Markussen

===================================================
smaller_sp <- large_sp [!(large_sp$ID %in% smaller_df$ID),]
Dan Pulter

====================================================
smaller_sp <- large_sp [large_sp$ID %in% smaller_df$ID == FALSE,]
Pedro Mardones
Torleif Markussen Lunde wrote: