简体   繁体   中英

Subset a large spatial dataframe based on certain counties

Im trying to subset a large spatial dataframe based on certain counties but I still get the same dataframe after subseting.

library(raster)
library(leaflet)
library(viridis)

# Get USA polygon data
USA <- getData("GADM", country = "usa", level = 2)

# Prepare data
subusa<-subset(USA,"Cheyenne"%in%USA$NAME_2&"Kimball"%in%USA$NAME_2)

I think you need

subusa<-subset(USA,"Cheyenne" == USA$NAME_2 | "Kimball"== USA$NAME_2)

This should retrieve rows where NAME_2 is Cheyenne or Kimball.

I think the original "Cheyenne"%in%USA$NAME&"Kimball"%in%USA$NAME resolves to TRUE&TRUE which equals a single logical value TRUE, which then gets recycled over every row of the data frame and returns all rows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM