View source: R/read_decennial.R
read_decennial | R Documentation |
This function retrieves data from summary file 1 (with urban/rural update) of decennial censuses. In addition to selected geographic headers and table contents, it also returns total population and coordinates of selected geographic areas, as well as summary levels and geographic components.
read_decennial(
year,
states,
table_contents = NULL,
areas = NULL,
geo_headers = NULL,
summary_level = NULL,
geo_comp = "total",
show_progress = TRUE
)
year |
year of the decennial census |
states |
vector of state abbreviations, for example "IN" or c("MA", "RI"). |
table_contents |
selected references of contents in census tables. Users
can choose a name for each reference, such as in
c("abc = PCT012F139", "fff = P0030008", "rural_p = P0020005").
Try to make names meaningful. To find the references of table contents
of interest, search with function |
areas |
For metro area, in the format like "New York metro".
For county, city, or town, must use the exact name as those in
|
geo_headers |
vector of references of selected geographci headers to be
included in the return. Search with |
summary_level |
select which summary level to keep, default to keep all. It takes strings
including "state", "county", "county subdivision", "place", "tract", "block group",
and "block" for the most common levels. It also take code for level. Search all codes with
|
geo_comp |
select which geographic component to keep, "*" to keep every geo-component,
"total" for "00", "urban" for "01", "urbanized area" for "04",
"urban cluster" for "28", "rural" for "43". For all other geographic component,
use code,
which can be found with |
show_progress |
show progress of file reading if TRUE. Turn off if FALSE, which is useful in RMarkdown output. |
A data.table whose columns include the selected geoheaders and table contents plus SUMLEV, GEOCOMP, and state.
## Not run:
# read one table and one area from one state
aaa = read_decennial(
year = 2010,
states = "UT",
table_contents = c("urban = P0020002", "rural = P0020005"),
geo_headers = "CBSA",
summary_level = "tract"
)
# read multiple table contents and areas from multiple states
bbb = read_decennial(
year = 2010,
states = c("UT", "RI"),
table_contents = c("urban = P0020002", "rural = P0020005"),
areas = c(
"place = ut62360",
"Providence city, RI",
"cousub = ri41500",
"cbsa = 39300"
),
summary_level = "block"
)
# read table contents of all county subdivisions in Providence metro
ccc <- read_decennial(
year = 2010,
states = "US",
table_contents = c("urban = P0020002", "rural = P0020005"),
geo_headers = "CBSA",
summary_level = "county subdivision",
geo_comp = "*"
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.