I have a vector of words
c('Apple','Orange','Apple','Carrot','Onion','Onion')
I want to categorize them in
list('fruit' = c('Apple', 'Orange'),
'vegetable' = c('Carrot','Onion')
The output I am looking for is
c('fruit', 'fruit', 'fruit', 'vegetable', 'vegetable', 'vegetable') .
My current approach is to convert each of them to data.table
and use merge
to get the categories. Is there any other simpler solution?