Skip to contents

With help of this function you can create GroupingConditions object, holding the basis of observation grouping. Objects of this class can be provided to complex functions to automatically group observations accordingly.

Usage

GroupConditions(
  conditions_category,
  ...,
  force_disjoint = TRUE,
  force_exhaustive = FALSE,
  .dots = list()
)

# S3 method for GroupConditions
print(x, ...)

# S3 method for GroupConditions
as.data.frame(x, ...)

Arguments

conditions_category

chracter value describing character of the group conditions. Mainly informative.

...

additional arguments to be passed to or from methods.

force_disjoint

boolean indicating if the condition formulas by default should be handled with force_disjoint strategy. By default TRUE. If TRUE, the first condition which will be met will indicate the group the observation will be assigned to.

force_exhaustive

boolean indicating if groups exhaustiveness should be forced in case when there are observations that don't pass any of the provided conditions. If TRUE, then they will be assigned to .NA group. Defaults to FALSE

.dots

formulas in form of a list

x

GroupConditions object

Value

GroupConditions object

Examples

# create GroupConditions with formula-style conditions per each group

sex_grouping <- GroupConditions(
  conditions_category = "Sex",
  "M" ~ sex == "M",
  "F" ~ sex == "F",
  "O" ~ !sex %in% c("M", "F")
)
print(sex_grouping)
#> <GroupConditions>
#> Conditions category: Sex
#> Tested variables: "sex"
#> 3 Groups:
#>M IF: sex == "M"
#>F IF: sex == "F"
#>O IF: !sex %in% c("M", "F")
#> Forced disjointedness by default: TRUE
#> Forced exhaustiveness by default: FALSE

# GroupConditions can also mark if the groups should be handled by default
# with forced disjoint (default `TRUE`) and exhaustiveness (default `FALSE`)

age_grouping <- GroupConditions(
  conditions_category = "Age",
  "to 20" ~ age < 20,
  "20 to 40" ~ age >= 20 & age <= 40,
  "40 to 60" ~ age >= 40 & age < 60,
  force_disjoint = FALSE,
  force_exhaustive = TRUE
)
print(age_grouping)
#> <GroupConditions>
#> Conditions category: Age
#> Tested variables: "age"
#> 3 Groups:
#>to 20 IF: age < 20
#>20 to 40 IF: age >= 20 & age <= 40
#>40 to 60 IF: age >= 40 & age < 60
#> Forced disjointedness by default: FALSE
#> Forced exhaustiveness by default: TRUE