Skip to content

Top k values

Source code

Description

Return the k largest elements. This has time complexity: O(n + k \log{}n - )

Usage

<Expr>$top_k(k)

Arguments

k Number of top values to get.

Value

Expr

Examples

library("polars")

pl$DataFrame(a = c(6, 1, 0, NA, Inf, NaN))$select(pl$col("a")$top_k(5))
#> shape: (5, 1)
#> ┌─────┐
#> │ a   │
#> │ --- │
#> │ f64 │
#> ╞═════╡
#> │ 6.0 │
#> │ 1.0 │
#> │ 0.0 │
#> │ inf │
#> │ NaN │
#> └─────┘