
Intersect two GroupAssignment
intersect_GroupAssignment.RdYou can intersect two GroupAssignment with this function.
Arguments
- GA1, GA2
GroupAssignment objects to intersect. No previously intersected objects can be intersected again.
- force_disjoint
boolean indicating if groups disjointedness should be forced in case when one observation would end in multiple intersections. If
TRUE, observation will remain only in the first intersection to which it will be assigned. Default toTRUE.- force_exhaustive
boolean indicating if elements that are not assigned to any of the intersecting groups should be gathered together in
.NA:.NAgroup
See also
Other observation grouping functions:
GroupAssignment(),
extract_observations()
Examples
sex_grouping <- GroupConditions(
conditions_category = "Sex",
"M" ~ sex == "M",
"F" ~ sex == "F",
"O" ~ !sex %in% c("M", "F")
)
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_exhaustive = TRUE,
force_disjoint = FALSE
)
# intersect two distinct GroupAssignements
intersected <- intersect_GroupAssignment(
GA1 = GroupAssignment(HEXACO_60, sex_grouping),
GA2 = GroupAssignment(HEXACO_60, age_grouping),
force_exhaustive = TRUE,
force_disjoint = FALSE
)
summary(intersected)
#> intersected <GroupAssignment>
#> Status
#> • Mode: index
#> • Total assigned: 204
#> • Disjointedness: FALSE; Forced: FALSE
#> • Exhaustiveness: TRUE; Forced: TRUE
#> Assignment [tested vars: `sex` and `age`]
#> • Group: M:to 20 [obs: 4]
#> • Group: M:20 to 40 [obs: 38]
#> • Group: M:40 to 60 [obs: 4]
#> • Group: M:.NA2 [obs: 0]
#> • Group: F:to 20 [obs: 16]
#> • Group: F:20 to 40 [obs: 128]
#> • Group: F:40 to 60 [obs: 6]
#> • Group: F:.NA2 [obs: 1]
#> • Group: O:to 20 [obs: 0]
#> • Group: O:20 to 40 [obs: 7]
#> • Group: O:40 to 60 [obs: 1]
#> • Group: O:.NA2 [obs: 1]