cut_by_group.RdCut by group
cut_by_group(df, col_data, col_group, group, new_col, as_factor = FALSE)(dataframe) with a column of data to be cut and a column specifying the group of each observation.
(string) the column containing the data to be cut.
(string) the column containing the names of the groups according to which the data should be
split.
(nested list) providing for each parameter value that should be analyzed in a categorical way: the
name of the parameter (string), a series of breakpoints (vector) where the first breakpoints is typically
-Inf and the last Inf, and a series of name which will describe each category (vector).
(string) the name of the new column in which the cut label should he stored.
(logical) if TRUE, the new column is of type factor else character.
group <- list(
list(
"Dose administered during constant dosing interval",
c(-Inf, 700, 900, 1200, Inf),
c("<700", "700-900", "900-1200", ">1200")
),
list(
"Total dose administered",
c(-Inf, 5000, 7000, 9000, Inf),
c("<5000", "5000-7000", "7000-9000", ">9000")
)
)
library(scda)
#>
sd <- synthetic_cdisc_data("rcd_2021_03_22")
adsl <- sd$adsl
adex <- dplyr::mutate(sd$adex, ANL01FL = "Y")
adex_gp <- cut_by_group(adex, "AVAL", "PARAM", group, "AVAL_gp")
head(adex_gp[, c("PARAM", "AVAL", "AVAL_gp")])
#> # A tibble: 6 × 3
#> PARAM AVAL AVAL_gp
#> <fct> <dbl> <chr>
#> 1 Dose administered during constant dosing interval 720 700-900
#> 2 Dose administered during constant dosing interval 720 700-900
#> 3 Dose administered during constant dosing interval 960 900-1200
#> 4 Dose administered during constant dosing interval 480 <700
#> 5 Dose administered during constant dosing interval 720 700-900
#> 6 Dose administered during constant dosing interval 480 <700