[R-sig-Geo] How to negate %in%

Jim Burke j.burke at earthlink.net
Mon May 25 21:34:48 CEST 2009


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:
> Hi 
>
> This (!) might work:
>
> aa <- 1:10
> bb <- 5:6
>
> aa[!aa %in% bb]
> [1]  1  2  3  4  7  8  9 10
>
> aa[aa %in% bb]
> [1] 5 6
>
> Best wishes
> Torleif
>
>
> On Monday 25 May 2009 08:13:40 pm Jim Burke wrote:
>   
>> I can subset a "SpatialPolygonsDataFrame" from a
>> data frame containing a smaller subset of IDs. For
>> example below.
>>
>> smaller_sp <- large_sp [large_sp$ID %in% smaller_df$ID,]
>>
>> Given the above how can I do the logically opposite from
>> the %in% operation and get all those IDs not %in%?
>>
>> I am processing two different sets of polygons (A,B) in
>> a loop. Operation is seeing in center points in polys B
>> fall in A. I would like to remove the spatial polygons
>> that I found (B) as I traverse the geographical area.
>>
>> Thanks,
>> Jim Burke
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>     
>
>
>
>
>



More information about the R-sig-Geo mailing list