Hi everyone,
I just want to know why is the 3rd code of chunks not working.
I would be happy if someone could show me how it should work with paste or paste0 function.
Thank you!
# data frame code chunks
my_basket = data.frame(ITEM_GROUP = c("Fruit","Fruit","Fruit","Fruit","Fruit","Vegetable","Vegetable","Vegetable","Vegetable","Dairy","Dairy","Dairy","Dairy","Dairy"),
ITEM_NAME = c("Apple","Banana","Orange","Mango","Papaya","Carrot","Potato","Brinjal","Raddish","Milk","Curd","Cheese","Milk","Paneer"),
Price = c(100,80,80,90,65,70,60,70,25,60,40,35,50,NA),
Tax = c(2,4,5,6,2,3,5,1,3,4,5,6,4,NA))
# this code of chunks work to create a new column called **Price_band** based on the existing column
my_basket %>%
mutate(Price_band = case_when(Price>=50 & Price <=70 ~ "Medium",
Price > 70 ~ "High", TRUE ~ "Low"))
# But when I use the paste function to create a new column(**Price_band**) based on the existing column, it won't work.
my_basket %>%
mutate(Price_band = case_when(ITEM_GROUP %in% c("Fruit","Dairy") ~ paste0(c("Fruit","Dairy")),
Price > 70 ~ "High", TRUE ~ "Low"))