希望将FIPS代码分配给数据集中的县的新R用户。我有多个点数据,并将县名附加到信息中,我希望将适当的FIPS代码分配给数据集中的所有县。
数据示例:
州StateFIPS县
DE 10苏塞克斯
DE 10苏塞克斯
德10肯特
DE 10苏塞克斯
我已经能够使用:DEdata$StateFIPS <- fips(DEdata$State)按状态附加FIPS。
但我不能使用这个fips功能的县级。是否要为州内的多个县分配FIPS代码?
发布于 2022-07-12 19:03:44
对于感兴趣的人,我可以使用TIGRIS包下载FIPS代码,然后用各种连接函数分配它。
##Assign FIPS by State
##DE_2016small$StateFIPS <- fips(DE_2016small$Residence_Addresses_State_2016)
##Assign FIPS by County
##Download FIPS from TidyCensus/Tigris and filter DE (Using TIGRIS) and filter
DE_counties <- counties("DE")
DE_counties <- DE_counties %>%
select(STATEFP, COUNTYFP, NAME)
DE_counties$geometry <- NULL
##Merge to match the County with its FIPS
DEwFIPS <- merge(DE_counties, DE_2016county, by.x = "NAME", by.y = "County", all = TRUE)
##Concatenate FIPS codes together
DEwFIPS$GEOID <- str_c(DE_FIPSbroad$STATEFP, DE_FIPSbroad$COUNTYFP, DE_FIPSbroad$Residence_Addresses_CensusTract_2016)
##Tidy data
DEwFIPS <- DEwFIPS %>% relocate(GEOID, .before = NAME)````https://stackoverflow.com/questions/72943922
复制相似问题