A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/jessecambon/tidygeocoder/issues/47 below:

Pad fips with 0's for `geocode()` · Issue #47 · jessecambon/tidygeocoder · GitHub

Skip to content Navigation Menu

Saved searches Use saved searches to filter your results more quickly

Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert Additional navigation options

Pad fips with 0's for geocode() #47

Description

Fantastic package! One thing for you to consider is to pad the fips from geocode(..., method = 'census', full_results = TRUE, return_type = "geographies") with 0's on the left to be consistent with the number of digits expected (outlined by the census: https://www.census.gov/programs-surveys/geography/guidance/geo-identifiers.html#par_textimage_8). Of course, you'll also have to force those columns to be character because of the leading zeros. For example, changing this:

library(dplyr)
library(tidygeocoder)

address_single <- tibble(singlelineaddress = c('11 Wall St, NY, NY', 
                                               '600 Peachtree Street NE, Atlanta, Georgia'))
address_components <- tribble(
  ~street                      , ~cty,               ~st,
  '11 Wall St',                  'NY',               'NY',
  '600 Peachtree Street NE',     'Atlanta',          'GA'
)

address_single %>% geocode(address = singlelineaddress, method = 'census',
                           full_results = TRUE, return_type = "geographies") %>%
  select(matches("(fips|tract|block)$"))
# A tibble: 2 x 4
  state_fips county_fips census_tract census_block
       <int>       <int>        <int>        <int>
1         36          61          700         1008
2         13         121         1900         2003

To this:

address_single %>% geocode(address = singlelineaddress, method = 'census',
                           full_results = TRUE, return_type = "geographies") %>%
  transmute(state_fips = stringr::str_pad(state_fips, 2, pad = "0"),
            county_fips = stringr::str_pad(county_fips, 3, pad = "0"),
            census_tract = stringr::str_pad(census_tract, 6, pad = "0"),
            census_block = stringr::str_pad(census_block, 4, pad = "0"))
# A tibble: 2 x 4
  state_fips county_fips census_tract census_block
  <chr>      <chr>       <chr>        <chr>       
1 36         061         000700       1008        
2 13         121         001900       2003 

If it would help I can submit a PR, I just need to dig into the code more to figure out if you can retain the 0's upstream or if you'll need to do it similar to how I did it (but avoiding the stringr import).

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4