Skip to content

Value counts

Source code

Description

Count all unique values and create a struct mapping value to count.

Usage

<Expr>$value_counts(..., sort = FALSE, parallel = FALSE, name = "count")

Arguments

Ignored.
sort Ensure the output is sorted from most values to least.
parallel Better to turn this off in the aggregation context, as it can lead to contention.
name Give the resulting count field a specific name, defaults to “count”.

Value

Expr

Examples

library(polars)

df = pl$DataFrame(iris)$select(pl$col("Species")$value_counts())
df
#> shape: (3, 1)
#> ┌───────────────────┐
#> │ Species           │
#> │ ---               │
#> │ struct[2]         │
#> ╞═══════════════════╡
#> │ {"virginica",50}  │
#> │ {"versicolor",50} │
#> │ {"setosa",50}     │
#> └───────────────────┘
df$unnest()$to_data_frame()
#>      Species count
#> 1  virginica    50
#> 2 versicolor    50
#> 3     setosa    50