Skip to contents

across_value_channels() and across_na_channels() are simple wrappers dplyr::across() that applies transformations to value or missing reason channels, respectively.

Usage

across_value_channels(.cols, .fns, .names = NULL, .unpack = FALSE)

across_na_channels(.cols, .fns, .names = NULL, .unpack = FALSE)

Arguments

.cols

<tidy-select> Columns to transform. You can't select grouping columns because they are already automatically handled by the verb (i.e. summarise() or mutate()).

.fns

Functions to apply to each of the selected columns. Possible values are:

  • A function, e.g. mean.

  • A purrr-style lambda, e.g. ~ mean(.x, na.rm = TRUE)

  • A named list of functions or lambdas, e.g. list(mean = mean, n_miss = ~ sum(is.na(.x)). Each function is applied to each column, and the output is named by combining the function name and the column name using the glue specification in .names.

Within these functions you can use cur_column() and cur_group() to access the current column and grouping keys respectively.

.names

A glue specification that describes how to name the output columns. This can use {.col} to stand for the selected column name, and {.fn} to stand for the name of the function being applied. The default (NULL) is equivalent to "{.col}" for the single function case and "{.col}_{.fn}" for the case where a list is used for .fns.

.unpack

[Experimental]

Optionally unpack data frames returned by functions in .fns, which expands the df-columns out into individual columns, retaining the number of rows in the data frame.

  • If FALSE, the default, no unpacking is done.

  • If TRUE, unpacking is done with a default glue specification of "{outer}_{inner}".

  • Otherwise, a single glue specification can be supplied to describe how to name the unpacked columns. This can use {outer} to refer to the name originally generated by .names, and {inner} to refer to the names of the data frame you are unpacking.

Value

like dplyr::across(), across_value_channels() and across_na_channels() return a tibble with one column for each column in .cols and each function in .fns

See also

Other interlaced tidy helpers: where_value_channel()