| rd_split | R Documentation |
Splits a REDCap dataset into separate datasets by form or event using the data dictionary. Supports both longitudinal and non-longitudinal projects and can return wide or long formats for repeated measures.
rd_split(
project = NULL,
data = NULL,
dic = NULL,
event_form = NULL,
which = NULL,
by = "form",
wide = FALSE
)
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. |
which |
Optional. A single form or event to extract. If not provided, all forms or events are returned. |
by |
Character. Criteria to split the dataset: |
wide |
Logical. If |
Handles checkbox variables and REDCap default variables (_complete, _timestamp) appropriately.
Columns of the data that aren't fields of the dictionary, nor the .factor or _mdc versions of its fields or the options of its checkbox fields (or the .factor version of the _complete field of a form), stop the function with an error that names them.
For form-based splits in longitudinal projects, uses event_form to map variables to events.
Wide format expands repeated instances into multiple columns per record. A form with only the record identifier gives one row per record.
Filtering by which allows extracting a single form or event.
Projects with repeated instruments are handled by filtering on the redcap_repeat_instrument variable (its codes). The column shows the label of each instrument (its factor version, from redcap_data()), or its code when the label is missing.
Depending on which and wide:
Without which, a tibble with one row per form (columns form, events in longitudinal projects, and df) or per event (columns events and df): the dataset of each form or event is in the list-column df (e.g. result$data$df[[1]], or result$data$df[result$data$form == "demographics"][[1]]). With wide = TRUE, the tibble of the forms also has the column max_repeated_instance, the largest number of rows of a record in each form (its events and repetitions): the wide columns are numbered by the position of each row of the record, not by its instance (e.g. the instances 2 and 5 of a record are the columns _1 and _2, and the maximum is 2). With which, the data.frame of that form or event.
The original REDCap dictionary.
The original event-form mapping (if applicable).
A summary message of the splitting operation.
Other process functions:
rd_checkbox(),
rd_dates(),
rd_delete_vars(),
rd_dictionary(),
rd_factor(),
rd_insert_na(),
rd_recalculate(),
rd_rlogic(),
rd_transform()
# Split by form and return wide format
result <- covican |>
rd_split(by = "form", wide = TRUE)
print(result)
# Split by event (long format)
result <- covican |>
rd_split(by = "event")
print(result)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.