GROUP BY + CASE statement

Your query would work already – except that you are running into naming conflicts or just confusing the output column (the CASE expression) with source column result, which has different content. … GROUP BY model.name, attempt.type, attempt.result … You need to GROUP BY your CASE expression instead of your source column: … GROUP BY model.name, … Read more

Case Statement Equivalent in R

case_when(), which was added to dplyr in May 2016, solves this problem in a manner similar to memisc::cases(). As of dplyr 0.7.0, for example: mtcars %>% mutate(category = case_when( cyl == 4 & disp < median(disp) ~ “4 cylinders, small displacement”, cyl == 8 & disp > median(disp) ~ “8 cylinders, large displacement”, TRUE ~ … Read more