Skip to main content

SLICE selects rows by position

Warning. This page is under construction.

head() and tail() take, respectively, the top few or the last few rows:

data %>% head( n = 10 )
data %>% tail( n = 10 )

slice_head() and slice_tail() do the same thing in groups:

data %>% group_by( country ) %>% head( n = 10 )
data %>% group_by( country ) %>% tail( n = 10 )

There is also slice_sample() which is useful - for example let's pick a random year by country:

data %>% group_by( country ) %>% slice_sample( n = 1 )