I have a data frame consisting of column n , and one of them is food . food Possible column values: apple , tomato , cabbage , sausage , beer , vodka , potato . I want to create a new column in the data data frame as follows: if food==apple or food==tomato or food==potato , then assign vegetables , otherwise assign only the value data$food .
So, if the data frame looks like this:
ID ..(some other columns).. food 1 apple 2 sausage 3 tomato 4 cabbage 5 vodka
then the result should be as follows:
ID ..(some other columns).. food category 1 apple vegetable 2 sausage sausage 3 tomato vegetable 4 cabbage vegetable 5 vodka vodka
How can i do this?
source share