Retrieve Census data from a given API

getCensus(
  name,
  vintage = NULL,
  key = Sys.getenv("CENSUS_KEY"),
  vars,
  region = NULL,
  regionin = NULL,
  time = NULL,
  date = NULL,
  period = NULL,
  monthly = NULL,
  show_call = FALSE,
  category_code = NULL,
  data_type_code = NULL,
  naics = NULL,
  pscode = NULL,
  naics2012 = NULL,
  naics2007 = NULL,
  naics2002 = NULL,
  naics1997 = NULL,
  sic = NULL,
  ...
)

Arguments

name

API name - e.g. acs5. See list at https://api.census.gov/data.html

vintage

Year of dataset, e.g. 2014 - not required for timeseries APIs

key

Your Census API key, gotten from https://api.census.gov/data/key_signup.html

vars

List of variables to get

region

Geography to get

regionin

Optional hierarchical geography to limit region

time, date, period, monthly

Optional arguments used for some time series APIs

show_call

List the underlying API call sent to the Census Bureau and other info

category_code, data_type_code

Arguments used in Economic Indicators Time Series API

naics, pscode

Arguments used in Annual Survey of Manufactures API

naics2012, naics2007, naics2002, naics1997, sic

Arguments used in Economy Wide Key Statistics APIs and Business Patterns APIs

...

Other valid parameters to pass to the Census API. Note: the APIs are case sensitive.

Examples

df <- getCensus(name = "acs/acs5", vintage = 2017, vars = c("B01001_001E", "NAME", "B01002_001E", "B19013_001E"), region = "tract:*", regionin = "state:06") head(df)
#> state county tract B01001_001E #> 1 06 083 002806 2430 #> 2 06 083 002913 3869 #> 3 06 083 002914 3386 #> 4 06 083 000400 5411 #> 5 06 083 001203 3029 #> 6 06 083 001800 941 #> NAME B01002_001E B19013_001E #> 1 Census Tract 28.06, Santa Barbara County, California 36.5 63259 #> 2 Census Tract 29.13, Santa Barbara County, California 46.3 91106 #> 3 Census Tract 29.14, Santa Barbara County, California 44.8 93125 #> 4 Census Tract 4, Santa Barbara County, California 37.0 74795 #> 5 Census Tract 12.03, Santa Barbara County, California 48.9 59135 #> 6 Census Tract 18, Santa Barbara County, California 42.0 50208
# Use American Community Survey variable groups to get all data from a given table. # This returns estimates as well as margins of error and annotation flags. acs_group <- getCensus(name = "acs/acs5", vintage = 2017, vars = c("NAME", "group(B19013)"), region = "county:*")
#> Warning: NAs introduced by coercion
head(acs_group)
#> state county NAME GEO_ID B19013_001E #> 1 72 073 Jayuya Municipio, Puerto Rico 0500000US72073 15615 #> 2 30 019 Daniels County, Montana 0500000US30019 53591 #> 3 24 023 Garrett County, Maryland 0500000US24023 48174 #> 4 30 079 Prairie County, Montana 0500000US30079 50850 #> 5 39 173 Wood County, Ohio 0500000US39173 58033 #> 6 08 011 Bent County, Colorado 0500000US08011 32500 #> B19013_001M NAME_1 B19013_001EA B19013_001MA #> 1 3424 NA <NA> <NA> #> 2 3318 NA <NA> <NA> #> 3 2234 NA <NA> <NA> #> 4 6481 NA <NA> <NA> #> 5 1604 NA <NA> <NA> #> 6 3442 NA <NA> <NA>
# Retreive block-level data within a specific tract using a nested regionin argument data2010 <- getCensus(name = "dec/sf1", vintage = 2010, vars = c("NAME","P001001"), region = "block:*", regionin = "state:36+county:027+tract:010000") head(data2010)
#> state county tract block #> 1 36 027 010000 1000 #> 2 36 027 010000 1011 #> 3 36 027 010000 1028 #> 4 36 027 010000 1001 #> 5 36 027 010000 1031 #> 6 36 027 010000 1002 #> NAME #> 1 Block 1000, Block Group 1, Census Tract 100, Dutchess County, New York #> 2 Block 1011, Block Group 1, Census Tract 100, Dutchess County, New York #> 3 Block 1028, Block Group 1, Census Tract 100, Dutchess County, New York #> 4 Block 1001, Block Group 1, Census Tract 100, Dutchess County, New York #> 5 Block 1031, Block Group 1, Census Tract 100, Dutchess County, New York #> 6 Block 1002, Block Group 1, Census Tract 100, Dutchess County, New York #> P001001 #> 1 31 #> 2 17 #> 3 41 #> 4 0 #> 5 0 #> 6 4
# Get poverty rates for children and all ages over time saipe <- getCensus(name = "timeseries/poverty/saipe", vars = c("NAME", "SAEPOVRT0_17_PT", "SAEPOVRTALL_PT"), region = "state:01", time = "from 2000 to 2017") head(saipe)
#> time state NAME SAEPOVRT0_17_PT SAEPOVRTALL_PT #> 1 2000 01 Alabama 20.5 14.6 #> 2 2001 01 Alabama 22.1 15.7 #> 3 2002 01 Alabama 21.6 15.4 #> 4 2003 01 Alabama 22.3 15.3 #> 5 2004 01 Alabama 22.6 16.1 #> 6 2005 01 Alabama 24.3 16.9
# Get county business patterns data for a specific NAICS sector cbp_2016 <- getCensus(name = "cbp", vintage = "2016", vars = c("EMP", "ESTAB", "NAICS2012_TTL", "GEO_TTL"), region = "state:*", naics2012 = "23") head(cbp_2016)
#> state EMP ESTAB NAICS2012_TTL GEO_TTL NAICS2012 #> 1 27 118033 16360 Construction Minnesota 23 #> 2 28 44551 3796 Construction Mississippi 23 #> 3 29 121494 13263 Construction Missouri 23 #> 4 26 138920 18803 Construction Michigan 23 #> 5 30 25036 5326 Construction Montana 23 #> 6 31 45909 6357 Construction Nebraska 23