Compare the levels of two factors
Question
Is it possible to evaluate two factors, to see whether they have the same numer of levels and if so which levels are not present in one or the other?
Solution
If factor1
and factor2
are your two factors, just look at levels(factor1)
and levels(factor2)
.
Same number of levels:
length(levels(factor1)) == length(levels(factor2))
Values in one and not the other:
setdiff(levels(factor1), levels(factor2))
setdiff(levels(factor2), levels(factor1))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow