Skip to Content
Modern R Programming Cookbook
book

Modern R Programming Cookbook

by Jaynal Abedin
October 2017
Beginner to intermediate
236 pages
7h 38m
English
Packt Publishing
Content preview from Modern R Programming Cookbook

How to do it...

Let's take a look at the following steps to see how we can use the filter() verb for data processing:

  1. Import the dataset from the CSV file and then apply the filter() verb from the dplyr library as follows:
        USAairlineData2016 <- read.csv("USAairlineData2016.csv", as.is            = T)        filterExample <- USAairlineData2016 %>%        filter(DEP_DELAY>30)
  1. Alternatively, the filter() code can be written without using the pipe operator as follows:
        filterExample2 <- filter(USAairlineData2016, DEP_DELAY>30)
  1. The base R functionality to achieve a similar task is as follows:
        filterExample3 <- USAairlineData2016        [USAairlineData2016$DEP_DELAY>30,]

However, the base R approach takes a bit longer than the dplyr approach.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

R Cookbook, 2nd Edition

R Cookbook, 2nd Edition

JD Long, Paul Teetor

Publisher Resources

ISBN: 9781787129054Supplemental Content