Created
July 4, 2021 14:07
-
-
Save mfherman/1714f9adcc33ef6a33d828662ea94bb2 to your computer and use it in GitHub Desktop.
Which census geographies add up?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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