Skip to content

Add state_table dataset #22

Description

@ASNDataAnalytics
# Source: https://www2.census.gov/geo/pdfs/maps-data/maps/reference/us_regdiv.pdf

state_table <-
  data.frame(
    state_name = state.name,
    state_usps = state.abb,
    census_region = as.character(state.region),
    census_division = as.character(state.division),
    stringsAsFactors = FALSE
  )

state_table <-
  rbind(
    state_table,
    data.frame(
      state_name = "District of Columbia",
      state_usps = "DC",
      census_region = "",
      census_division = "",
      stringsAsFactors = FALSE
    )
  )

state_table <-
  state_table[order(state_table$state_name), ]

state_table$census_region[
  state_table$census_region == "North Central"
] <- "Midwest"
state_table$census_region[state_table$state_usps == "DC"] <- "South"
state_table$census_division[state_table$state_usps == "DC"] <- "South Atlantic"

region_map <- c(Northeast = 1, Midwest = 2, South = 3, West = 4)

division_map <- c(
  "New England" = 1,
  "Middle Atlantic" = 2,
  "East North Central" = 3,
  "West North Central" = 4,
  "South Atlantic" = 5,
  "East South Central" = 6,
  "West South Central" = 7,
  "Mountain" = 8,
  "Pacific" = 9
)

state_table$census_region_number <- region_map[state_table$census_region]
state_table$census_division_number <- division_map[state_table$census_division]

fips_map <- c(
  AL = "01",
  AK = "02",
  AZ = "04",
  AR = "05",
  CA = "06",
  CO = "08",
  CT = "09",
  DE = "10",
  DC = "11",
  FL = "12",
  GA = "13",
  HI = "15",
  ID = "16",
  IL = "17",
  IN = "18",
  IA = "19",
  KS = "20",
  KY = "21",
  LA = "22",
  ME = "23",
  MD = "24",
  MA = "25",
  MI = "26",
  MN = "27",
  MS = "28",
  MO = "29",
  MT = "30",
  NE = "31",
  NV = "32",
  NH = "33",
  NJ = "34",
  NM = "35",
  NY = "36",
  NC = "37",
  ND = "38",
  OH = "39",
  OK = "40",
  OR = "41",
  PA = "42",
  RI = "44",
  SC = "45",
  SD = "46",
  TN = "47",
  TX = "48",
  UT = "49",
  VT = "50",
  VA = "51",
  WA = "53",
  WV = "54",
  WI = "55",
  WY = "56"
)

state_table$state_fips <- fips_map[state_table$state_usps]

rownames(state_table) <- NULL

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions