in R Language by
Pipeline in R Language

▼ Show 1 Answer

0 votes

The creation of a dataset requires a lot of operations, such as:

  • importing
  • merging
  • selecting
  • filtering
  • and so on

The dplyr library comes with a practical operator, %>%, called the pipeline. The pipeline feature makes the manipulation clean, fast and less prompt to error.

This operator is a code which performs steps without saving intermediate steps to the hard drive. If you are back to our example from above, you can select the variables of interest and filter them. We have three steps:

  • Step 1: Import data: Import the gps data
  • Step 2: Select data: Select GoingTo and DayOfWeek
  • Step 3: Filter data: Return only Home and Wednesday

We can use the hard way to do it:

# Step 1
step_1 <- read.csv(PATH)

# Step 2 
step_2 <- select(step_1, GoingTo, DayOfWeek)

# Step 3 
step_3 <- filter(step_2, GoingTo == "Home", DayOfWeek == "Wednesday")

Learn More with Madanswer

Related questions

0 votes
asked Nov 14, 2019 in R Language by MBarbieri