nest_for_ard {cards}R Documentation

ARD Nesting

Description

This function is similar to tidyr::nest(), except that it retains rows for unobserved combinations (and unobserved factor levels) of by variables, and unobserved combinations of stratifying variables.

The levels are wrapped in lists so they can be stacked with other types of different classes.

Usage

nest_for_ard(
  data,
  by = NULL,
  strata = NULL,
  key = "data",
  rename_columns = TRUE,
  list_columns = TRUE
)

Arguments

data

(data.frame)
a data frame

by, strata

(character)
columns to nest by/stratify by. Arguments are similar, but with an important distinction:

by: data frame is nested by all combinations of the columns specified, including unobserved combinations and unobserved factor levels.

strata: data frame is nested by all observed combinations of the columns specified.

Arguments may be used in conjunction with one another.

key

(string)
the name of the new column with the nested data frame. Default is "data".

rename_columns

(logical)
logical indicating whether to rename the by and strata variables. Default is TRUE.

list_columns

(logical)
logical indicating whether to put levels of by and strata columns in a list. Default is TRUE.

Value

a nested tibble

Examples

nest_for_ard(
  data =
    ADAE |>
      dplyr::left_join(ADSL[c("USUBJID", "ARM")], by = "USUBJID") |>
      dplyr::filter(AOCCSFL %in% "Y"),
  by = "ARM",
  strata = "AESOC"
)

[Package cards version 0.1.0 Index]