I am having some trouble creating a new variable in R in a dataframe conditioned to an external list of values:
# Sample dataframe employee <- c('John Doe','Peter Gynn','Jolie Hope') salary <- c(21000, 23400, 26800) color <- c('blue', `green`, `red`) data.frame(employee, salary, color) #List of colors and categories color_categories <- list( cold = c("blue", "green"), warm = c("red", "orange"))
I want to create a new variable in the dataframe with the color category depending on the color chosen by each employee, so I want to get something like this result:
employee salary color category 1 John Doe 21000 blue cold 2 Peter Gynn 23400 green cold 3 Jolie Hope 26800 red warm
Of course, this example uses very simple data, but I have to solve this problem with a much larger dataframe and a 220 codes list organized in categories to classify the dataframe observations...
Thank you very much!!!