View source: R/all_groups_identical.R
all_groups_identical | R Documentation |
Checks whether two grouping factors contain the same groups, looking only at the group members, allowing for different group names / identifiers.
all_groups_identical(x, y)
x, y |
Two grouping factors ( N.B. Both are converted to |
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.
Whether all groups in `x`
are the same in `y`
, memberwise. (logical)
Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk
Other grouping functions:
collapse_groups_by
,
collapse_groups()
,
fold()
,
group_factor()
,
group()
,
partition()
,
splt()
# 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.