slice_head | R Documentation |
Choose rows in a data.table. Grouped data.tables grab rows within each group.
slice_head(.df, n = 5, ..., .by = NULL, by = NULL)
slice_tail(.df, n = 5, ..., .by = NULL, by = NULL)
slice_max(.df, order_by, n = 1, ..., with_ties = TRUE, .by = NULL, by = NULL)
slice_min(.df, order_by, n = 1, ..., with_ties = TRUE, .by = NULL, by = NULL)
slice(.df, ..., .by = NULL)
slice_sample(
.df,
n,
prop,
weight_by = NULL,
replace = FALSE,
.by = NULL,
by = NULL
)
.df |
A data.frame or data.table |
n |
Number of rows to grab |
... |
Integer row values |
.by , by |
Columns to group by |
order_by |
Variable to arrange by |
with_ties |
Should ties be kept together. The default |
prop |
The proportion of rows to select |
weight_by |
Sampling weights |
replace |
Should sampling be performed with ( |
df <- data.table(
x = 1:4,
y = 5:8,
z = c("a", "a", "a", "b")
)
df %>%
slice(1:3)
df %>%
slice(1, 3)
df %>%
slice(1:2, .by = z)
df %>%
slice_head(1, .by = z)
df %>%
slice_tail(1, .by = z)
df %>%
slice_max(order_by = x, .by = z)
df %>%
slice_min(order_by = y, .by = z)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.