
Subset rows using their positions
Source:R/slice_head-rd.R, R/slice_head.R
slice_head.duckplyr_df.RdThis is a method for the dplyr::slice_head() generic.
slice_head() selects the first rows.
Usage
# S3 method for class 'duckplyr_df'
slice_head(.data, ..., n, prop, by = NULL)Arguments
- .data
A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr). See Methods, below, for more details.
- ...
For
slice(): <data-masking> Integer row values.Provide either positive values to keep, or negative values to drop. The values provided must be either all positive or all negative. Indices beyond the number of rows in the input are silently ignored.
For
slice_*(), these arguments are passed on to methods.- n, prop
Provide either
n, the number of rows, orprop, the proportion of rows to select. If neither are supplied,n = 1will be used. Ifnis greater than the number of rows in the group (orprop > 1), the result will be silently truncated to the group size.propwill be rounded towards zero to generate an integer number of rows.A negative value of
norpropwill be subtracted from the group size. For example,n = -2with a group of 5 rows will select 5 - 2 = 3 rows;prop = -0.25with 8 rows will select 8 * (1 - 0.25) = 6 rows.- by
-
<
tidy-select> Optionally, a selection of columns to group by for just this operation, functioning as an alternative togroup_by(). For details and examples, see ?dplyr_by.
Fallbacks
There is no DuckDB translation in slice_head.duckplyr_df()
if
byorpropis provided,with a negative
n.
These features fall back to dplyr::slice_head(), see vignette("fallback") for details.
Examples
library(duckplyr)
df <- data.frame(x = 1:3)
df <- slice_head(df, n = 2)
df
#> x
#> 1 1
#> 2 2