8.4 Use slice to choose rows - Video Tutorials & Practice Problems
Video duration:
1m
Play a video:
Video transcript
<v Voiceover>Sometimes you</v> don't want to subset your data based on some sort of condition. You might want to specify certain rows. We can do that in Dplyr using the slice function. We'll say dia pipe slice one through five. This will give us the first five rows. We could have asked for the first 10 rows. Dia pipe slice one through 10. Now we have the first 10 rows. Not counting the data that's piped in, slice takes one argument, and that is a vector of indices. So let's say we want rows one, three, and five through 10. So we say dia pipe slice, then the vector. One comma three comma five through 10. Slicing allows you to subset your data when you know the row index as opposed to some condition.