all_groups_identical {groupdata2} | R Documentation |
Test if two grouping factors contain the same groups
Description
Checks whether two grouping factors contain the same groups, looking only at the group members, allowing for different group names / identifiers.
Usage
all_groups_identical(x, y)
Arguments
x , y |
Two grouping factors ( N.B. Both are converted to |
Details
Both factors are sorted by `x`
.
A grouping factor is created with new groups starting at the values in
`y`
which differ from the previous row
(i.e. group()
with method = "l_starts"
and n = "auto"
).
A similar grouping factor is created for `x`
,
to have group identifiers range from 1
to the number of groups.
The two generated grouping factors are tested for equality.
Value
Whether all groups in `x`
are the same in `y`
, memberwise. (logical)
Author(s)
Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk
See Also
Other grouping functions:
collapse_groups_by
,
collapse_groups()
,
fold()
,
group_factor()
,
group()
,
partition()
,
splt()
Examples
# Attach groupdata2
library(groupdata2)
# Same groups, different identifiers
x1 <- c(1, 1, 2, 2, 3, 3)
x2 <- c(2, 2, 1, 1, 4, 4)
all_groups_identical(x1, x2) # TRUE
# Same groups, different identifier types
x1 <- c(1, 1, 2, 2, 3, 3)
x2 <- c("a", "a", "b", "b", "c", "c")
all_groups_identical(x1, x2) # TRUE
# Not same groups
# Note that all groups must be the same to return TRUE
x1 <- c(1, 1, 2, 2, 3, 3)
x2 <- c(1, 2, 2, 3, 3, 3)
all_groups_identical(x1, x2) # FALSE
# Different number of groups
x1 <- c(1, 1, 2, 2, 3, 3)
x2 <- c(1, 1, 1, 2, 2, 2)
all_groups_identical(x1, x2) # FALSE