get_ces_subset {ces} | R Documentation |
Get Subset of Variables from Canadian Election Study Dataset
Description
This function allows users to get a specific subset of variables from a CES dataset. It's useful for selecting only the variables of interest for a specific analysis.
Usage
get_ces_subset(
year,
variables = NULL,
regex = FALSE,
format = "tibble",
clean = TRUE,
use_cache = TRUE
)
Arguments
year |
A character string indicating the year of the CES data. |
variables |
A character vector of variable names to select from the dataset. If NULL (default), all variables are returned. |
regex |
A logical indicating whether to use regex matching for variable names. Default is FALSE. |
format |
A character string indicating the format to return the data in. Default is "tibble". Options include "tibble", "data.frame", or "raw". |
clean |
Logical indicating whether to clean the data. Default is TRUE. |
use_cache |
Logical indicating whether to use cached data if available. Default is TRUE. |
Value
A tibble or data.frame containing the requested CES data variables.
Examples
# Get only vote choice and demographic variables from 2019
variables <- c("vote_choice", "age", "gender", "province", "education")
ces_subset <- get_ces_subset("2019", variables)
# Get all variables containing "vote" in their name (using regex)
vote_vars <- get_ces_subset("2019", "vote", regex = TRUE)