read_ipums_agg | R Documentation |
Read a .csv file from an extract downloaded from an IPUMS aggregate data collection (IPUMS NHGIS or IPUMS IHGIS).
To read spatial data from an NHGIS extract, use read_ipums_sf()
.
read_ipums_agg(
data_file,
file_select = NULL,
vars = NULL,
col_types = NULL,
n_max = Inf,
guess_max = min(n_max, 1000),
var_attrs = c("val_labels", "var_label", "var_desc"),
remove_extra_header = TRUE,
file_encoding = NULL,
verbose = TRUE
)
data_file |
Path to a .zip archive containing an IPUMS NHGIS or IPUMS IHGIS extract or a single .csv file from such an extract. |
file_select |
If |
vars |
Names of variables to include in the output. Accepts a
vector of names or a tidyselect selection.
If |
col_types |
One of
See |
n_max |
Maximum number of lines to read. |
guess_max |
For .csv files, maximum number of lines to use for guessing column types. Will never use more than the number of lines read. |
var_attrs |
Variable attributes to add from the codebook (.txt) file included in the extract. Defaults to all available attributes. See |
remove_extra_header |
If This header row is not
usually needed as it contains similar information to that
included in the |
file_encoding |
Encoding for the file to be loaded. For NHGIS extracts, defaults to ISO-8859-1. For IHGIS extracts, defaults to UTF-8. If the default encoding produces unexpected characters, adjust the encoding here. |
verbose |
Logical controlling whether to display output when loading
data. If Will be overridden by |
A tibble
containing the data found in
data_file
read_ipums_sf()
to read spatial data from an IPUMS extract.
read_nhgis_codebook()
or read_ihgis_codebook()
to read metadata about
an IPUMS aggregate data extract.
ipums_list_files()
to list files in an IPUMS extract.
nhgis_file <- ipums_example("nhgis0972_csv.zip")
ihgis_file <- ipums_example("ihgis0014.zip")
# Provide the .zip archive directly to load the data inside:
read_ipums_agg(nhgis_file)
# For extracts that contain multiple files, use `file_select` to specify
# a single file to load. This accepts a tidyselect expression:
read_ipums_agg(ihgis_file, file_select = matches("AAA_g0"), verbose = FALSE)
# Or an index position:
read_ipums_agg(ihgis_file, file_select = 2, verbose = FALSE)
# Variable metadata is automatically attached to data, if available
ihgis_data <- read_ipums_agg(ihgis_file, file_select = 2, verbose = FALSE)
ipums_var_info(ihgis_data)
# Column types are inferred from the data. You can
# manually specify column types with `col_types`. This may be useful for
# geographic codes, which should typically be interpreted as character values
read_ipums_agg(nhgis_file, col_types = list(MSA_CMSAA = "c"), verbose = FALSE)
# You can also read in a subset of the data file:
read_ipums_agg(
nhgis_file,
n_max = 15,
vars = c(GISJOIN, YEAR, D6Z002),
verbose = FALSE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.