Return the number of rows in each group
Description
Return the number of rows in each group
Usage
<GroupBy>$len(name = NULL)
Arguments
name
|
Assign a name to the resulting column. If NULL, defaults to
“len”.
|
Value
A polars DataFrame
Examples
library("polars")
df <- pl$DataFrame(
a = c("Apple", "Apple", "Orange"),
b = c(1, NA, 2)
)
df$group_by("a")$len()
#> shape: (2, 2)
#> ┌────────┬─────┐
#> │ a ┆ len │
#> │ --- ┆ --- │
#> │ str ┆ u32 │
#> ╞════════╪═════╡
#> │ Orange ┆ 1 │
#> │ Apple ┆ 2 │
#> └────────┴─────┘
#> shape: (2, 2)
#> ┌────────┬─────┐
#> │ a ┆ n │
#> │ --- ┆ --- │
#> │ str ┆ u32 │
#> ╞════════╪═════╡
#> │ Orange ┆ 1 │
#> │ Apple ┆ 2 │
#> └────────┴─────┘