R most common string value

I have a dataframe looks like this:

id cat1 cat2 cat3 cat4
1 apple banana banana orange
2 orange banana apple orange

I want to find a most common categories for each id. so the table will look like:

id cat
1 banana
2 orange

is there a simple way in R? thank you

Read more here: https://stackoverflow.com/questions/66275788/r-most-common-string-value

Content Attribution

This content was originally published by user9776841 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: