Let's say I have an R vector of type
vector1 = c("dog", "cat", "fish") vector2 = c("fish", "fish", "fish")
The first vector
vector1 contains three distinct elements: dog, cat, fish
vector2 contains all the same elements.
I'm looking for an efficient way to check this property in an R vector, preferably using base R.
My idea would be to use the following:
TRUE, then there's only 1 element. If
FALSE, there are many.
Alternatively, you can use
> all(vector1 == vector1)  FALSE > all(vector2 == vector2)  TRUE