Fix binding resulted missingness in shadow matrices
Source:R/shadow.R
shadow_replace_binding_missing.Rd
This function replaces the missing values in the shadow matrices.
This is done by checking if the values in
shadow matrices are both NA. If they are, the value in the shadow
matrix is replaced with Missing due to joining
.
Usage
shadow_replace_binding_missing(
data,
shadow,
id_cols = union(get_id_cols_abcd(), get_id_cols_hbcd()),
replacement = "Missing due to joining"
)
Arguments
- data
tibble. The data.
- shadow
tibble. The shadow matrix.
- id_cols
character (vector). The possible unique identifier columns. The data does not need to have all of these columns, but if they are present, they will be used to identify unique rows (Default: identifier columns used in ABCD and HBCD). For example, the ABCD data usually has only
participant_id
andsession_id
, so ifrun_id
is provided, it will be ignored.- replacement
character. The value to replace the missing values with.
Details
Data and shadow requirements: The two dataframes must have the same columns and the same number of rows. They must have the same column names, but the order of the columns does not matter. It is recommended to use the same column order and the same row order (by ID columns) in both dataframes, which saves some processing time.
Examples
shadow <- tibble::tibble(
participant_id = c("1", "2", "3"),
session_id = c("1", "2", "3"),
var1 = c("Unknown", NA, NA),
var2 = c("Wish not to answer", NA, NA)
)
data <- tibble::tibble(
participant_id = c("1", "2", "3"),
session_id = c("1", "2", "3"),
var1 = c(NA, NA, 1),
var2 = c(NA, 2, NA)
)
shadow_replace_binding_missing(data, shadow)
#> Error in check_pkgs(pkgs = list(NBDCtoolsData = list(remote = "nbdc-datahub/NBDCtoolsData")), abort_msg = "NBDCtoolsData package is not installed", quiet = quiet): NBDCtoolsData package is not installed
#> ✖ `NBDCtoolsData`
#> ℹ Please install the missing packages with:
#>
#> renv::install(c("nbdc-datahub/NBDCtoolsData"))