How to combine values within a variable

For reference, please see FAQ: What's a reproducible example (`reprex`) and how do I do one? because it generally help to have a bit more to go on. In this case, I'll have to make a guess about what kind of object your variable is, and I'm going to assume a list

shopping <- c("apples","lettuce","soap","banana", "tofu", "grape")
> new_shop <- recode(shopping, apples = "Fruit")
> new_shop <- recode(new_shop, banana = "Fruit")
> new_shop <- recode(new_shop, grape = "Fruit")
> new_shop
[1] "Fruit"   "lettuce" "soap"    "Fruit"   "tofu"    "Fruit"  
1 Like