group_map.: A version of group_map that provides a named list in return

View source: R/dplyr-facile.R

group_map.R Documentation

A version of group_map that provides a named list in return

Description

dplyr::group_map returns an unnamed list, but a named list is often handy https://github.com/tidyverse/dplyr/issues/4223#issuecomment-469269857

Usage

group_map.(.data, .f, ..., .keep = FALSE)

Arguments

.data

a grouped tibble

.f

a function of formula to apply to each group. If a function, it is used as is. It should have at least 2 formal arguments. If a formula, e.g. ~ head(.x), it is converted to a function. In the formula, you can use: * . or .x to refer to the subset of rows of .tbl for the given group * .y to refer to the key, a one row tibble with one column per grouping variable that identifies the group

Value

a list of elemnts returned by .f over the grouped elements in .data

Examples

# no names
iris |> group_by(Species) |> group_map(~ nrow(.x))

# with names
iris |> group_by(Species) |> group_map.(~ nrow(.x))

facileverse/FacileData documentation built on April 12, 2025, 11:50 a.m.