Go to TogaWare.com Home Page. Data Science Desktop Survival Guide
by Graham Williams
Duck Duck Go



CLICK HERE TO VISIT THE UPDATED SURVIVAL GUIDE

Case Statement

20200421 Many languages support a case or switch statement. R did not originally have a case statement but it was introduced through tidyr as dplyr::case_when():
library(dplyr)

with(ds,
     case_when(max_temp > 35 ~ "hot",
               max_temp > 25 ~ "warm",
               max_temp > 18 ~ "mild",
               max_temp > 12 ~ "cool",
               max_temp >  0 ~ "cold",
               TRUE          ~ "freezing"))
##   [1] "mild"     "warm"     "warm"     "warm"     "warm"     "warm"    
##   [7] "mild"     "warm"     "warm"     "warm"     "warm"     "mild"    
##  [13] "mild"     "mild"     "mild"     "warm"     "mild"     "mild"    
##  [19] "mild"     "warm"     "warm"     "warm"     "warm"     "warm"    
##  [25] "warm"     "warm"     "warm"     "warm"     "warm"     "mild"    
##  [31] "mild"     "warm"     "mild"     "warm"     "warm"     "hot"     
....


Support further development by purchasing the PDF version of the book.
Other online resources include the GNU/Linux Desktop Survival Guide.
Books available on Amazon include Data Mining with Rattle and Essentials of Data Science.
Popular open source software includes rattle and wajig.
Hosted by Togaware, a pioneer of free and open source software since 1984.
Copyright © 2000-2020 Togaware Pty Ltd. . Creative Commons ShareAlike V4.