Load multiple years of data from the Current Population Survey.
This function will also download the data for you, if it is not present in
the given dir.
Usage
cps_read(
years = seq(1994, 2024, 2),
dir = cps_data_dir(),
cols = cpsvote::cps_cols,
names_col = "new_name",
join_dfs = TRUE
)Arguments
- years
Which years to read in. Thie function will read data from files in
dirwhose names contain these 4-digit years.- dir
The folder where the CPS data files live. These files should follow a naming scheme that contains the 4-digit year of the results in question, and have a ".zip" or ".gz" extension. Defaults to
cps_data_dir(), which returns~/cps_dataunless overridden viaoptions(cpsvote.datadir = "your/path").- cols
Which columns to read. This must be a data frame, with required columns
start_pos,end_pos, andyear. The default value iscps_cols, which reads from the listcpsvote::cps_cols. Seevignette("add-variables")for details about how to specify a different set ofcols.- names_col
The column in
colsthat contains column names for the specified columns. If none exists, usenames_col = NULL- join_dfs
Whether to combine all of the years into a single data frame, or leave them as a list of data frames. Defaults to
TRUEwith a warning.