| rd_factor | R Documentation |
Converts variables in a REDCap dataset with associated .factor columns into actual factor variables, while allowing the exclusion of specific variables. Ensures consistency with the dataset and preserves variable labels.
rd_factor(
project = NULL,
data = NULL,
dic = NULL,
event_form = NULL,
exclude = NULL
)
project |
A list containing the REDCap data, dictionary, and event mapping (expected |
data |
A |
dic |
A |
event_form |
Only applicable for longitudinal projects (presence of events). Event-to-form mapping for longitudinal projects. |
exclude |
Optional character vector of variable names (use original names without the |
The function looks for columns ending in .factor and replaces the original variable values with those .factor values (converted to factors). The variables in exclude, the system columns below and the variables whose labels are of several codes (with a warning) keep both columns. A .factor column that isn't a factor (e.g. text, after modifying the data) is converted to a factor, with the levels in the order of the options of the dictionary. It preserves variable labels. The exclude argument must contain base variable names (no .factor suffix); if any .factor names are passed to exclude the function will throw an informative error. The columns redcap_event_name, redcap_repeat_instrument and redcap_data_access_group (and their .factor counterparts) are handled specially to avoid altering event or access-group data. A .factor column whose original variable no longer exists (e.g. removed with rd_delete_vars()), also of these columns, is removed with a warning.
Use rd_factor() before rd_dictionary(): the branching logic and calculations that rd_dictionary() translates to R compare the variables with their original codes, so they stop working once the variables are factors. If the dictionary already has logic translated to R that uses any of the converted variables, a warning is shown.
A list with the following elements:
The transformed dataset with .factor columns applied as factors.
The dictionary used (unchanged).
The event-form mapping used (if applicable).
A brief text summary of the transformation.
Other process functions:
rd_checkbox(),
rd_dates(),
rd_delete_vars(),
rd_dictionary(),
rd_insert_na(),
rd_recalculate(),
rd_rlogic(),
rd_split(),
rd_transform()
## Not run:
result <- rd_factor(covican)
result <- rd_factor(covican, exclude = c("available_analytics", "urine_culture"))
transformed_data <- result$data
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.