ipeaGIT / geobr

Easy access to official spatial data sets of Brazil in R and Python
https://ipeagit.github.io/geobr/
786 stars 118 forks source link

How to get a Subset of States by municipality #266

Closed ragapack closed 2 years ago

ragapack commented 2 years ago

Hi, How I can do something like this? Brasil <- read_municipality(year=2018, code_muni= c("GO", "DF") ) I tried to get the 2 states and after this merge but ...

Brasil_GO <- read_municipality(year=2018, code_muni="GO") Using year 2018 Brasil_DF <- read_municipality(year=2018,code_muni="DF") Using year 2018 Brasil <- merge(Brasil_GO,Brasil_DF) Error in merge.sf(Brasil_GO, Brasil_DF) : merge on two sf objects not supported

rafapereirabr commented 2 years ago

There are two options here:

1. Read all and filter

Brasil <- read_municipality(year=2018, code_muni= 'all')
df_go <- subset(Brasil, abbrev_state %in% c("GO", "DF"))

2. Read each state separately and then bind

Brasil_GO <- read_municipality(year=2018, code_muni="GO")
Brasil_DF <- read_municipality(year=2018,code_muni="DF")
df_go <- rbind(Brasil_GO,Brasil_DF)