Download Demographic Data for Five-digit ZCTAs
Source:R/zi_get_demographics.R
zi_get_demographics.Rd
This function returns demographic data for five-digit ZIP Code Tabulation Areas (ZCTAs), which are rough approximations of many (but not all) USPS ZIP codes.
Usage
zi_get_demographics(year, variables = NULL, table = NULL,
survey, output = "tidy", zcta = NULL, key = NULL)
Arguments
- year
A four-digit numeric scalar for year.
zippeR
currently supports data for from 2010 to 2022. Differentsurvey
products are available for different years. See thesurvey
parameter for more details- variables
A character scalar or vector of variable IDs.
- table
A character scalar of a table ID (only one table may be requested per call).
- survey
A character scalar representing the Census product. It can be either a Decennial Census product (either
"sf1"
or"sf3"
) or an American Community Survey product (either"acs1"
,"acs3"
, or"acs5"
). For Decennial Census calls, only the 2010 Census is available. In addition, if a variable cannot be found in"sf1"
, the function will look in"sf3"
. Also note that"acs3"
was discontinued after 2013.- output
A character scalar; one of
"tidy"
(long output) or"wide"
depending on the type of data format you want. If you are planning to pass these data tozi_aggregate()
, you must choose"tidy"
. If you are leaving these data as five-digit ZCTAs and are planning to join them with geometric data,"wide"
is the strongly encouraged format.- zcta
An optional vector of ZCTAs that demographic data are requested for. If this is
NULL
, data will be returned for all ZCTAs. If a vector is supplied, only data for those requested ZCTAs will be returned. The vector can be created withzi_get_geometry()
and should only contain five-digit ZCTAs.- key
A Census API key, which can be obtained at https://api.census.gov/data/key_signup.html. This can be omitted if
tidycensus::census_api_key()
has been used to write your key to your.Renviron
file. You can check whether an API key has been written to.Renviron
by usingSys.getenv("CENSUS_API_KEY")
.
Examples
# \donttest{
# download all ZCTAs
zi_get_demographics(year = 2012, variables = "B01003_001", survey = "acs5")
#> # A tibble: 33,120 × 4
#> GEOID variable estimate moe
#> <chr> <chr> <dbl> <dbl>
#> 1 00601 B01003_001 18544 271
#> 2 00602 B01003_001 41640 147
#> 3 00603 B01003_001 54540 735
#> 4 00606 B01003_001 6593 270
#> 5 00610 B01003_001 29141 180
#> 6 00612 B01003_001 69017 1500
#> 7 00616 B01003_001 10750 1084
#> 8 00617 B01003_001 24733 171
#> 9 00622 B01003_001 5923 984
#> 10 00623 B01003_001 44943 984
#> # ℹ 33,110 more rows
# limit output to subset of ZCTAs
## download all ZCTAs in Missouri, intersects method
mo20 <- zi_get_geometry(year = 2020, state = "MO", method = "intersect")
#> ZCTAs can take several minutes to download. To cache the data and avoid re-downloading in future R sessions, set `options(tigris_use_cache = TRUE)`
#>
|
| | 0%
|
|= | 1%
|
|= | 2%
|
|== | 2%
|
|== | 3%
|
|== | 4%
|
|=== | 4%
|
|=== | 5%
|
|==== | 5%
|
|==== | 6%
|
|===== | 7%
|
|===== | 8%
|
|====== | 8%
|
|====== | 9%
|
|======= | 10%
|
|======== | 11%
|
|======== | 12%
|
|========= | 12%
|
|========= | 13%
|
|========== | 14%
|
|========== | 15%
|
|=========== | 15%
|
|=========== | 16%
|
|============ | 16%
|
|============ | 17%
|
|============ | 18%
|
|============= | 18%
|
|============= | 19%
|
|============== | 19%
|
|============== | 20%
|
|============== | 21%
|
|=============== | 21%
|
|=============== | 22%
|
|================ | 22%
|
|================ | 23%
|
|================= | 24%
|
|================= | 25%
|
|================== | 25%
|
|================== | 26%
|
|=================== | 27%
|
|=================== | 28%
|
|==================== | 28%
|
|==================== | 29%
|
|===================== | 29%
|
|===================== | 30%
|
|===================== | 31%
|
|====================== | 31%
|
|====================== | 32%
|
|======================= | 32%
|
|======================= | 33%
|
|======================== | 34%
|
|======================== | 35%
|
|========================= | 35%
|
|========================= | 36%
|
|========================== | 37%
|
|========================== | 38%
|
|=========================== | 38%
|
|=========================== | 39%
|
|============================ | 39%
|
|============================ | 40%
|
|============================ | 41%
|
|============================= | 41%
|
|============================= | 42%
|
|============================== | 42%
|
|============================== | 43%
|
|============================== | 44%
|
|=============================== | 44%
|
|=============================== | 45%
|
|================================ | 45%
|
|================================ | 46%
|
|================================= | 47%
|
|================================= | 48%
|
|================================== | 48%
|
|================================== | 49%
|
|=================================== | 49%
|
|=================================== | 50%
|
|==================================== | 51%
|
|==================================== | 52%
|
|===================================== | 52%
|
|===================================== | 53%
|
|====================================== | 54%
|
|====================================== | 55%
|
|======================================= | 55%
|
|======================================= | 56%
|
|======================================== | 57%
|
|======================================== | 58%
|
|========================================= | 58%
|
|========================================= | 59%
|
|========================================== | 60%
|
|========================================== | 61%
|
|=========================================== | 61%
|
|=========================================== | 62%
|
|============================================ | 62%
|
|============================================ | 63%
|
|============================================= | 64%
|
|============================================= | 65%
|
|============================================== | 65%
|
|============================================== | 66%
|
|=============================================== | 66%
|
|=============================================== | 67%
|
|=============================================== | 68%
|
|================================================ | 68%
|
|================================================ | 69%
|
|================================================= | 69%
|
|================================================= | 70%
|
|================================================= | 71%
|
|================================================== | 71%
|
|================================================== | 72%
|
|=================================================== | 72%
|
|=================================================== | 73%
|
|==================================================== | 74%
|
|==================================================== | 75%
|
|===================================================== | 75%
|
|===================================================== | 76%
|
|====================================================== | 77%
|
|====================================================== | 78%
|
|======================================================= | 78%
|
|======================================================= | 79%
|
|======================================================== | 79%
|
|======================================================== | 80%
|
|======================================================== | 81%
|
|========================================================= | 81%
|
|========================================================= | 82%
|
|========================================================== | 82%
|
|========================================================== | 83%
|
|=========================================================== | 84%
|
|=========================================================== | 85%
|
|============================================================ | 85%
|
|============================================================ | 86%
|
|============================================================= | 87%
|
|============================================================= | 88%
|
|============================================================== | 88%
|
|============================================================== | 89%
|
|=============================================================== | 89%
|
|=============================================================== | 90%
|
|=============================================================== | 91%
|
|================================================================ | 91%
|
|================================================================ | 92%
|
|================================================================= | 92%
|
|================================================================= | 93%
|
|================================================================= | 94%
|
|================================================================== | 94%
|
|================================================================== | 95%
|
|=================================================================== | 95%
|
|=================================================================== | 96%
|
|==================================================================== | 97%
|
|==================================================================== | 98%
|
|===================================================================== | 98%
|
|===================================================================== | 99%
|
|======================================================================| 100%
## download demographic data
zi_get_demographics(year = 2012, variables = "B01003_001", survey = "acs5",
zcta = mo20$GEOID)
#> # A tibble: 1,024 × 4
#> GEOID variable estimate moe
#> <chr> <chr> <dbl> <dbl>
#> 1 51640 B01003_001 1687 145
#> 2 52542 B01003_001 340 126
#> 3 52573 B01003_001 84 61
#> 4 52626 B01003_001 1499 230
#> 5 63005 B01003_001 17741 706
#> 6 63010 B01003_001 36304 985
#> 7 63011 B01003_001 37114 907
#> 8 63012 B01003_001 10334 779
#> 9 63013 B01003_001 1697 489
#> 10 63014 B01003_001 483 150
#> # ℹ 1,014 more rows
# }