I have a data frame called animals containing different sized columns that have some common and uncommon elements among each other as shown below:
Dog Cat Lion Dog
Cat Lion Dog Shark
Lion Dog Shark Cat
Shark Shark Cat Lion
Whale Seal Moose
Seal Whale
Deer
What I want to do is identify all the common elements within each column, exclude the uncommon elements and combine the common elements into one column like this:
Dog
Cat
Lion
Shark
So far I've tried identifying the duplicated elements using duplicated(animals) and then extract the duplicated elements using animals[duplicated(animals)] but this gives no results. Does anyone have a better method?