Skip to content

Get the last n values of a list

Source code

Description

Get the last n values of a list

Usage

<Expr>$list$tail(n = 5L)

Arguments

n Number of values to return for each sublist. Can be an Expr. Strings are parsed as column names.

Value

Expr

Examples

library("polars")

df = pl$DataFrame(
  s = list(1:4, c(10L, 2L, 1L)),
  n = 1:2
)
df$with_columns(
  tail_by_expr = pl$col("s")$list$tail("n"),
  tail_by_lit = pl$col("s")$list$tail(2)
)
#> shape: (2, 4)
#> ┌─────────────┬─────┬──────────────┬─────────────┐
#> │ s           ┆ n   ┆ tail_by_expr ┆ tail_by_lit │
#> │ ---         ┆ --- ┆ ---          ┆ ---         │
#> │ list[i32]   ┆ i32 ┆ list[i32]    ┆ list[i32]   │
#> ╞═════════════╪═════╪══════════════╪═════════════╡
#> │ [1, 2, … 4] ┆ 1   ┆ [4]          ┆ [3, 4]      │
#> │ [10, 2, 1]  ┆ 2   ┆ [2, 1]       ┆ [2, 1]      │
#> └─────────────┴─────┴──────────────┴─────────────┘