Skip to content

Get the last n rows.

Source code

Description

Get the last n rows.

Usage

<DataFrame>$tail(n = 5L)

Arguments

n Number of rows to return. If a negative value is passed, return all rows except the first abs(n).

Value

A DataFrame

Examples

library(polars)

df = pl$DataFrame(foo = 1:5, bar = 6:10, ham = letters[1:5])

df$tail(3)
#> shape: (3, 3)
#> ┌─────┬─────┬─────┐
#> │ foo ┆ bar ┆ ham │
#> │ --- ┆ --- ┆ --- │
#> │ i32 ┆ i32 ┆ str │
#> ╞═════╪═════╪═════╡
#> │ 3   ┆ 8   ┆ c   │
#> │ 4   ┆ 9   ┆ d   │
#> │ 5   ┆ 10  ┆ e   │
#> └─────┴─────┴─────┘
# Pass a negative value to get all rows except the first `abs(n)`.
df$tail(-3)
#> shape: (2, 3)
#> ┌─────┬─────┬─────┐
#> │ foo ┆ bar ┆ ham │
#> │ --- ┆ --- ┆ --- │
#> │ i32 ┆ i32 ┆ str │
#> ╞═════╪═════╪═════╡
#> │ 4   ┆ 9   ┆ d   │
#> │ 5   ┆ 10  ┆ e   │
#> └─────┴─────┴─────┘