This function allows you to manually insert a missing value into certain variables (`vars`) if the specified filter/s (`filter`) are satisfied. It's particularly useful for checkboxes without a gatekeeper question in the branching logic. Note that the variable is only transformed in the events where both the variable and the filter evaluation are present, so they must have at least one event in common.
Arguments
- ...
List containing the data, the dictionary and the event if it's needed. Should be the output of the function `redcap_data`.
- data
Data frame containing data from REDCap. If the list is specified, this argument is not needed.
- dic
Data frame containing the dictionary read from REDCap. If the list is specified, this argument is not needed.
- event_form
Data frame containing the correspondence of each event with each form. If the list is specified, this argument is not needed.
- vars
Character vector containing the names of the variables to be transformed.
- filter
Character vector containing the logic to be evaluated directly. If each logic is TRUE, the corresponding variable in `vars` is set to missing.
Examples
table(is.na(covican$data$potassium))
#>
#> FALSE TRUE
#> 250 92
data <- rd_insert_na(covican,
vars = "potassium",
filter = "age < 65")
#> Warning: The variable to be transformed (potassium) is present in more events than the events where the corresponding filter is evaluated. Only the rows of those events in common will be transformed (baseline_visit_arm_1).
table(data$potassium)
#>
#> 2.5 2.9 3 3.04 3.1 3.2 3.25 3.3 3.4 3.41 3.47 3.48 3.54 3.6 3.67 3.69
#> 1 1 4 1 4 6 1 6 4 1 1 1 1 8 1 1
#> 3.7 3.71 3.8 3.9 3.95 4 4.02 4.03 4.04 4.09 4.1 4.11 4.2 4.23 4.24 4.25
#> 4 1 11 19 1 8 2 2 1 1 13 1 11 1 2 1
#> 4.28 4.3 4.37 4.38 4.39 4.4 4.45 4.5 4.56 4.58 4.59 4.6 4.61 4.7 4.71 4.79
#> 2 6 1 1 1 7 1 7 1 2 1 6 1 3 1 1
#> 4.8 4.83 4.9 5 5.1 5.2 5.4 5.5 5.7 5.8 6.6 6.7 7.15 8.7
#> 3 1 4 2 3 2 2 2 1 1 1 1 1 1