getCensus: Retrieve Census data from a given API

Description Usage Arguments Examples

View source: R/getcensus_functions.R

Description

Retrieve Census data from a given API

Usage

1
2
3
4
5
6
getCensus(name, vintage = NULL, key = Sys.getenv("CENSUS_KEY"), vars,
  region = NULL, regionin = NULL, time = NULL, date = NULL,
  period = NULL, monthly = NULL, 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

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
df <- getCensus(name = "acs/acs5", vintage = 2017,
vars = c("B01001_001E", "NAME", "B01002_001E", "B19013_001E"),
region = "tract:*", regionin = "state:06")
head(df)

# 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:*")
head(acs_group)

# 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)

# Retreive block-level data for Decennial Census sf1, 2000
# Note, for this dataset a tract needs to be specified to retrieve blocks
data2000 <- getCensus(name = "sf1",
vintage = 2000,
vars = c("P001001", "P003001"),
region = "block:*",
regionin = "state:36+county:27+tract:010000")
head(data2000)

# 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)

# 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)

censusapi documentation built on May 2, 2019, 9:39 a.m.