slice: Select rows by position.

Description Usage Arguments See Also Examples

View source: R/manip.r

Description

Slice does not work with relational databases because they have no intrinsic notion of row order. If you want to perform the equivalent operation, use filter() and row_number().

Usage

1
2
3
slice(.data, ...)

slice_(.data, ..., .dots)

Arguments

.data

A tbl. All main verbs are S3 generics and provide methods for tbl_df, tbl_dt and tbl_sql.

...

Integer row values

.dots

Used to work around non-standard evaluation. See vignette("nse") for details.

See Also

Other single.table.verbs: arrange, filter, mutate, select, summarise

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
slice(mtcars, 1L)
slice(mtcars, n())
slice(mtcars, 5:n())

by_cyl <- group_by(mtcars, cyl)
slice(by_cyl, 1:2)

# Equivalent code using filter that will also work with databases,
# but won't be as fast for in-memory data. For many databases, you'll
# need to supply an explicit variable to use to compute the row number.
filter(mtcars, row_number() == 1L)
filter(mtcars, row_number() == n())
filter(mtcars, between(row_number(), 5, n()))

sctyner/dplyr050 documentation built on May 17, 2019, 2:22 p.m.