Skip to content

Commit

Permalink
Add usa_states reference data
Browse files Browse the repository at this point in the history
  • Loading branch information
elipousson committed May 26, 2024
1 parent 9267f78 commit cdaaff9
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
16 changes: 16 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,19 @@
#' }
#' @details <https://docs.google.com/spreadsheets/d/1YX3NBDkkoDXHs88KDfPS_QoS9-1j_C_q8UAyjPznfzA/edit?usp=sharing>
"jam_values"

#' U.S. States Reference Data
#'
#' A reference table of state names, abbreviations, regions, and divisions.
#'
#' @format A data frame with 56 rows and 7 variables:
#' \describe{
#' \item{`state`}{State name}
#' \item{`state_abb`}{State USPS abbreviation}
#' \item{`STATE_GEOID`}{State GeoID}
#' \item{`division`}{Census Division name}
#' \item{`DIVISION_GEOID`}{Census Division GeoID}
#' \item{`region`}{Census Region name}
#' \item{`REGION_GEOID`}{Census Region GeoID}
#'}
"usa_states"
41 changes: 41 additions & 0 deletions data-raw/usa_states.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
states <- tigris::states()

divisions <- tigris::divisions()

regions <- tigris::regions()

usa_states <- states |>
sf::st_drop_geometry() |>
select(
state = NAME,
state_abb = STUSPS,
STATE_GEOID = GEOID,
DIVISION_GEOID = DIVISION,
REGION_GEOID = REGION
) |>
left_join(
divisions |>
sf::st_drop_geometry() |>
select(
DIVISION_GEOID = GEOID,
division = NAME
)
) |>
left_join(
regions |>
sf::st_drop_geometry() |>
select(
REGION_GEOID = GEOID,
region = NAME
)
) |>
relocate(
DIVISION_GEOID,
.after = division
) |>
relocate(
REGION_GEOID,
.after = region
)

usethis::use_data(usa_states, overwrite = TRUE)
Binary file added data/usa_states.rda
Binary file not shown.
25 changes: 25 additions & 0 deletions man/usa_states.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cdaaff9

Please sign in to comment.