Using the simple dataframe below, I wanto create a new column that contains a 1 for instances where City = "Toronto" and PostInjury = "0-1", a 2 for instances when City= "Montreal" and PostInjury ="6-10", and a 3 for everything else.
I want to use mutate and if_else, but not sure how to use this combination to conditionally recode multiple column combinations into one new column without intermediate steps? I can use two if_else statements to create two new columns, then combine them with Tidyr's unite and then recode, but that seems very tedious.
Am I missing something elegant? I have a feeling I am. Is there a way to use if_else in this way with dplyr, or perhaps with case_when?
City<-c("Toronto", "Toronto", "Montreal","Ottawa","Montreal",
"Hamilton","Peterborough","Toronto","Hamilton","Montreal")
Client<-c("Cl1","Cl2","Cl3","Cl4","Cl5","Cl6","Cl7","Cl8","Cl9","Cl10")
PostInjury<-c("0-1","6-10","0-1","2-5","6-10","0-1","11-15","0-1","0-1","6-10")
DF<- data.frame(City,Client,PostInjury)