Selecting columns with dplyr

In the last recipe, we introduced how to use the filter and slice functions to subset and slice data by rows. In this recipe, we will present how to select particular columns from the dataset using the select function.

Getting ready

Ensure that you completed the Enhancing a data.frame with a data.table recipe to load purchase_view.tab and purchase_order.tab as both data.frame and data.table into your R environment.

You also need to make sure that you have a version of R higher than 3.1.2 installed on your operating system.

How to do it…

Perform the following steps to select columns from the dataset:

  1. First, let's select the Quantity and Price columns from the dataset:
    > select.quantity.price <- select(order.dt, Quantity, ...

Get R for Data Science Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.