Last chance! 50% off unlimited learning
Sale ends in
Helper function to create a new SMQ variable in ADAE that consists of all adverse events belonging to
selected Standardized/Customized queries. The new dataset will only contain records of the adverse events
belonging to any of the selected baskets. Remember that na_str
must match the needed pre-processing
done with df_explicit_na()
to have the desired output.
h_stack_by_baskets(
df,
baskets = grep("^(SMQ|CQ).+NAM$", names(df), value = TRUE),
smq_varlabel = "Standardized MedDRA Query",
keys = c("STUDYID", "USUBJID", "ASTDTM", "AEDECOD", "AESEQ"),
aag_summary = NULL,
na_str = ""
)
A data.frame
with variables in keys
taken from df
and new variable SMQ containing
records belonging to the baskets selected via the baskets
argument.
(data.frame
)
data set containing all analysis variables.
(character
)
variable names of the selected Standardized/Customized queries.
(string
)
a label for the new variable created.
(character
)
names of the key variables to be returned along with the new variable created.
(data.frame
)
containing the SMQ baskets and the levels of interest for the final SMQ
variable. This is useful when there are some levels of interest that are not observed in the df
dataset.
The two columns of this dataset should be named basket
and basket_name
.
(string
)
string used to replace all NA
or empty values in the output.
adae <- tern_ex_adae[1:20, ] %>% df_explicit_na()
h_stack_by_baskets(df = adae)
aag <- data.frame(
NAMVAR = c("CQ01NAM", "CQ02NAM", "SMQ01NAM", "SMQ02NAM"),
REFNAME = c(
"D.2.1.5.3/A.1.1.1.1 aesi", "X.9.9.9.9/Y.8.8.8.8 aesi",
"C.1.1.1.3/B.2.2.3.1 aesi", "C.1.1.1.3/B.3.3.3.3 aesi"
),
SCOPE = c("", "", "BROAD", "BROAD"),
stringsAsFactors = FALSE
)
basket_name <- character(nrow(aag))
cq_pos <- grep("^(CQ).+NAM$", aag$NAMVAR)
smq_pos <- grep("^(SMQ).+NAM$", aag$NAMVAR)
basket_name[cq_pos] <- aag$REFNAME[cq_pos]
basket_name[smq_pos] <- paste0(
aag$REFNAME[smq_pos], "(", aag$SCOPE[smq_pos], ")"
)
aag_summary <- data.frame(
basket = aag$NAMVAR,
basket_name = basket_name,
stringsAsFactors = TRUE
)
result <- h_stack_by_baskets(df = adae, aag_summary = aag_summary)
all(levels(aag_summary$basket_name) %in% levels(result$SMQ))
h_stack_by_baskets(
df = adae,
aag_summary = NULL,
keys = c("STUDYID", "USUBJID", "AEDECOD", "ARM"),
baskets = "SMQ01NAM"
)
Run the code above in your browser using DataLab