-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Data Wrangling with R
By :

Slicing and filtering a dataset are two similar ways to zoom in on a desired part of the data. In tidyverse, the dplyr
library deals with the most common data wrangling tasks. Slicing and filtering are among those tasks, as well as the select()
function, as we will see.
As discussed in Chapter 7, slicing cuts out unwanted parts of the dataset, returning just part of the rows and/or columns. There is more than one way to slice a dataset, and we will learn the more interesting functions to do that, starting with the most basic one, as follows. In the code, when we use .
, it means we are considering everything from the object that precedes it, which is df
, followed by a slicing notation. Rows 1 to 5 and columns 1 to 4:
# Slicing rows 1 to 5, columns 1 to 4. df %>% .[1:5, c(1:4)]
The result is shown in Figure 8.5.
Figure 8.5 – Sliced dataset
To provide summary notes about the previous code: the dataset object...
Change the font size
Change margin width
Change background colour