View source: R/prep_add_missing_codes.R
prep_add_missing_codes | R Documentation |
NA
s based on rulesInsert missing codes for NA
s based on rules
prep_add_missing_codes(
resp_vars,
study_data,
meta_data,
label_col,
rules,
use_value_labels,
overwrite = FALSE
)
resp_vars |
variable list the name of the measurement variables to be
modified, all from |
study_data |
data.frame the data frame that contains the measurements |
meta_data |
data.frame the data frame that contains metadata attributes of study data |
label_col |
variable attribute the name of the column in the metadata with labels of variables |
rules |
data.frame with the columns:
|
use_value_labels |
logical In rules for factors, use the value labels,
not the codes. Defaults to |
overwrite |
logical Also insert missing codes, if the values are not
|
a list
with the entries:
ModifiedStudyData
: Study data with NA
s replaced by the CODE_VALUE
ModifiedMetaData
: Metadata having the new codes amended in the columns
JUMP_LIST
or MISSING_LIST
, respectively
## Not run:
load(system.file("extdata", "study_data.RData", package = "dataquieR"))
load(system.file("extdata", "meta_data.RData", package = "dataquieR"))
vn <- subset(r$ModifiedMetaData, LABEL == "PREGNANT_0", VAR_NAMES)[[1]]
rules <- tibble::tribble(
~resp_vars, ~CODE_CLASS, ~CODE_LABEL, ~CODE_VALUE, ~RULE,
"PREGNANT_0", "JUMP", "No pregnancies in males", "9999", '[SEX_0]=1',
)
r <- prep_add_missing_codes(NA, study_data, meta_data,
label_col = "LABEL", rules, use_value_labels = FALSE)
subset(r$ModifiedMetaData, LABEL == "PREGNANT_0", JUMP_LIST)
subset(meta_data, LABEL == "PREGNANT_0", JUMP_LIST)
table(study_data[[vn]])
table(r$ModifiedStudyData[[vn]])
r <- prep_add_missing_codes(NA, study_data, meta_data,
label_col = "LABEL", rules, use_value_labels = FALSE, overwrite = TRUE)
table(study_data[[vn]])
table(r$ModifiedStudyData[[vn]])
rules <- tibble::tribble(
~resp_vars, ~CODE_CLASS, ~CODE_LABEL, ~CODE_VALUE, ~RULE,
"PREGNANT_0", "JUMP", "No pregnancies in males", "9999", '[SEX_0]="males"',
)
r <- prep_add_missing_codes(NA, study_data, meta_data,
label_col = "LABEL", rules, use_value_labels = TRUE, overwrite = FALSE)
table(study_data[[vn]])
table(r$ModifiedStudyData[[vn]])
rules <- tibble::tribble(
~resp_vars, ~CODE_CLASS, ~CODE_LABEL, ~CODE_VALUE, ~RULE,
"PREGNANT_0", "JUMP", "No pregs in males", "9999", '[v00002]="males"',
)
r <- prep_add_missing_codes(NA, study_data, meta_data,
label_col = "LABEL", rules, use_value_labels = TRUE, overwrite = FALSE)
table(study_data[[vn]])
table(r$ModifiedStudyData[[vn]])
devtools::load_all(".")
study_data$v00002 <- ifelse(study_data$v00002 == "0", "females", "males")
meta_data[meta_data$LABEL == "SEX_0", "VALUE_LABELS"] <- "females|males"
rules <- tibble::tribble(
~resp_vars, ~CODE_CLASS, ~CODE_LABEL, ~CODE_VALUE, ~RULE,
"PREGNANT_0", "JUMP", "No pregnancies in males", "9999", '[v00002]="males"',
)
r <- prep_add_missing_codes(NA, study_data, meta_data,
label_col = "LABEL", rules, use_value_labels = TRUE, overwrite = FALSE)
table(study_data[[vn]])
table(r$ModifiedStudyData[[vn]])
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.