Skip to content

Commit

Permalink
Merge pull request #145 from Merck/add_na_name
Browse files Browse the repository at this point in the history
add argument na_name
  • Loading branch information
nanxstats authored Jul 19, 2023
2 parents 05625a6 + fde864d commit feaafcd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 5 additions & 2 deletions R/collect_n_subject.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#' @param id A character vector of subject identifier.
#' @param group A factor vector of group name.
#' @param par A character vector of parameter name.
#' @param na A character string used to label missing values. Defaults to `"Missing"`.
#' @param use_na A character value for whether to include `NA` values
#' in the table. See the `useNA` argument in [base::table()] for more details.
#'
Expand All @@ -38,14 +39,16 @@
#' n_subject(r2rtf_adae$USUBJID, r2rtf_adae$TRTA)
#' n_subject(r2rtf_adae$USUBJID, r2rtf_adae$TRTA, r2rtf_adae$SEX)
#' n_subject(r2rtf_adae$USUBJID, r2rtf_adae$TRTA, r2rtf_adae$SEX, use_na = "always")
#' n_subject(r2rtf_adae$USUBJID, r2rtf_adae$TRTA, r2rtf_adae$SEX, na = "Null")
n_subject <- function(id,
group,
par = NULL,
na = "Missing",
use_na = c("ifany", "no", "always")) {
use_na <- match.arg(use_na)

if ("factor" %in% class(group)) {
u_group <- c(as.character(levels(group)), "Missing")
u_group <- c(as.character(levels(group)), na)
} else {
stop("n_subject: group variable must be a factor")
}
Expand All @@ -61,7 +64,7 @@ n_subject <- function(id,
db <- data.frame(id = id, group = group, par = par)
res <- table(unique(db)[, c("group", "par")], useNA = use_na)
name <- colnames(res)
name[is.na(name)] <- "Missing"
name[is.na(name)] <- na

n_row <- nrow(res)
n_col <- ncol(res)
Expand Down
11 changes: 10 additions & 1 deletion man/n_subject.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit feaafcd

Please sign in to comment.