Check If Grouping Factors Contain Same Groups in R (Example Code)
In this article, I’ll illustrate how to test if two grouping factors contain the same groups in the R programming language.
Creation of Example Data
vec_a <- factor(c("X", "Y", "Y", "X", "X", "X")) # Create two factor vectors vec_b <- factor(c("foo", "bar", "bar", "foo", "foo", "foo")) |
vec_a <- factor(c("X", "Y", "Y", "X", "X", "X")) # Create two factor vectors vec_b <- factor(c("foo", "bar", "bar", "foo", "foo", "foo"))
Example: Apply all_groups_identical() Function to Test Equality of Grouping Factors
install.packages("groupdata2") # Install & load groupdata2 package library("groupdata2") |
install.packages("groupdata2") # Install & load groupdata2 package library("groupdata2")
all_groups_identical(vec_a, vec_b) # Test if grouping factors contain same groups # [1] TRUE |
all_groups_identical(vec_a, vec_b) # Test if grouping factors contain same groups # [1] TRUE
Further Resources & Related Articles
Furthermore, you might have a look at the related R posts on this homepage.