0

New R user looking to assign the FIPS code to the counties within a dataset. I have multiple point data with a county name attached to the information, and I want to assign the appropriate FIPS code to all counties within the dataset.

Data example:

State StateFIPS County
DE 10 Sussex

DE 10 Sussex

DE 10 Kent

DE 10 Sussex

I have been able to attach the FIPS by state using: DEdata$StateFIPS <- fips(DEdata$State)

But I am unable to use this fips function for the County level. Is there anyway to assign the FIPS code for multiple counties within the state?

TeaNoMilk
  • 15
  • 5

1 Answers1

0

For anybody interested, I was able to download the FIPS codes using the TIGRIS package, and then assign it with various join functions.

  ##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)````
TeaNoMilk
  • 15
  • 5
  • Any time you provide an answer to a question, please try to make the solution reproducible. Ideally, you would provide your example data as a data.frame and then use the code employed in your answer. As it is now, your answer (a) does not load required packages (it looks like you are using stringr, dplyr, and perhaps some other packages) and (b) doesn't reproduce the problem then solve it. More information on reproducible examples here https://stackoverflow.com/help/minimal-reproducible-example – socialscientist Jul 14 '22 at 05:29