13.13 Chaining with dplyr
- Code (e.g. above) is sometimes difficult to read and the arguments are very long
dplyrit is possible to use the
x %>% f(y)turns into
x(e.g. a data set) is inserted into the function on the right of
>to be a function which does the above
- The resulting code seems a bit more intuitive
swiss %>% # Stick swiss into the functions below consecutively select(Fertility, Infant.Mortality, Examination) %>% filter(Fertility > 82) %>% filter(Infant.Mortality < 24) # DO TRY THAT AT HOME!!!