I saw a lot of similar questions but none of the answers have worked for me... Here's my example data
company<-c("c1","c1","c2","c2","c2","c3","c3","c3","c4","c4", "c4")
subsegment<- c("Sub2","Sub3", "Sub1","Sub2", "Sub3", "Sub1","Sub2", "Sub3", "Sub1","Sub2", "Sub3")
values<-c(120,300,30,300,1800,10,96,277, 10, 400, 1100)
df<- data.frame(company,subsegment, values)
company.keys<-c("c1","c2","c3","c4")
company.description <- c("CocaCola", "Pepsi", "Boing", "Perrier")
lookup.company<- as.data.frame(company.keys, company.description)
subseg.keys<- c("Sub1", "Sub2", "Sub3")
subseg.description<- c("SoftDrink", "Snacks", "Other")
lookup.subseg<- as.data.frame(subseg.keys, subseg.description)
I have my original data frame df I want to take the column 'company' and go search in 'lookup.company' to replace the keys with the description. I know how to do it like this but I want a way that will use my lookup data frames:
df$subsegment[df$subsegment == "Sub1"] <- "SoftDrink"
I tried but I get an error:
df %>%
mutate_at(subsegment, funs(ifelse(. %in% lookup.subseg$subseg.keys, lookup.subseg$subseg.description[match(., lookup.subseg$subseg.keys)], .)))
Error: Warning message:
funs() was deprecated in dplyr 0.8.0.
Please use a list of either functions or lambdas:
As I said, I know it has been asked before but none of the answers I saw seemed to work for me I would like to use dplyr for the solution