Skip to content

Instantly share code, notes, and snippets.

@mfherman
Created July 4, 2021 14:07
Show Gist options
  • Save mfherman/1714f9adcc33ef6a33d828662ea94bb2 to your computer and use it in GitHub Desktop.
Save mfherman/1714f9adcc33ef6a33d828662ea94bb2 to your computer and use it in GitHub Desktop.
Which census geographies add up?
library(tidycensus)
library(tidyverse)
state <- get_decennial(
geography = "state",
variables = "P001001",
state = "CA"
)
tract <- get_decennial(
geography = "tract",
variables = "P001001",
state = "CA"
)
ca_county_codes <- fips_codes %>%
filter(state == "CA") %>%
distinct(county_code)
block <- map_dfr(
ca_county_codes,
~ get_decennial(
geography = "block",
variables = "P001001",
state = "CA",
county = .x
)
)
zcta <- get_decennial(
geography = "zcta",
variables = "P001001",
state = "CA"
)
sum(state$value) == sum(tract$value)
sum(state$value) == sum(block$value)
sum(state$value) == sum(zcta$value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment