The Pipe Operator %>%

The Pipe Operator %>%

The Pipe Operator %>% 

What it is

In R, %>% is called the "pipe" operator.  It  takes the output of one statement and uses it as the input for the following statement. Another way of saying this is that it "pipes" or "chains" together a string of consecutive functions.

Example 

When you read %>%, you can think of it as saying, "then".  For example, take the code: 

If you read it out loud, you might say something like:

"First, you take the Fingers data, then

 you filter the data to include only rows where Sex is  “female”,  then 

you create a histogram of the height variable"  

Your output would be a histogram of heights for females in the Fingers data frame:

 histogram of female heights in the Fingers data frame

Learn more about the pipe operator 

Check out this article to learn more: 

https://www.datacamp.com/community/tutorials/pipe-r-tutorial



    • Related Articles

    • filter()

      The filter() function will find rows/cases where the conditions indicated are true. It is often used with operators such as the following: > (greater than) < (less than) >= (greater than or equal to) <= (less than or equal to) == (equal to) != (not ...