spatial vector data manipulation using r for multiple value filtering

I can select a single value for "ds-01" only how can i filter multiple characters at once
the value to be filtered in district_name columun : district_name=c("ds-01", "ds-02", "ds-03", ds-04")

data.shp<- shapefile("data.shp") 
ds-01<- data.shp[data.shp$district_name=="ds-01", ]

is there a possible solution for this

Have you considered something along the lines of %in% infix operator instead of equals ==, e.g.

data.shp<- shapefile("data.shp") 
ds_1234<- data.shp[data.shp$district_name %in% c("ds-01", "ds-02", "ds-03", "ds-04"), ]

alternatively using {dplyr} workflow

library(dplyr)
data_filtered <- data.shp %>%
  filter(district_name %in%  c("ds-01", "ds-02", "ds-03", "ds-04"))

Thanks a lot!!! :raised_hand: :raised_hand:

1 Like

This topic was automatically closed 7 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.