"Every student can learn, just not on the same day, or the same way."
― George Evans
"Every student can learn, just not on the same day, or the same way."
― George Evans
Piping allows you to take the output of one function and pipe it as the input of the next function. You can string along several pipes to form a single chain.
%>%
Ex: say you want to apply functions h()
and g()
and then f()
on data x
. You can do
f(g(h(x)))
ORx %>% h() %>% g() %>% f()
This
Pipes are always directed to the first argument of any function. The following three bits of R code do the same thing, extract all january flights:
library(nycflights13) data(flights) # Bit 1: No piping filter(flights, month == 1) # Bit 2: Piping. Note no comma flights %>% filter(month == 1) # Bit 3: Piping across multiple lines (preferred for legibility) flights %>% filter(month==1)