Learn R Programming

tidytable (version 0.5.1)

mutate_across.: Mutate multiple columns simultaneously

Description

Mutate multiple columns simultaneously.

Usage

mutate_across.(.df, .cols = everything(), .fns, ..., by = NULL)

dt_mutate_across(.df, .cols = everything(), .fns, ..., by = NULL)

Arguments

.df

A data.frame or data.table

.cols

vector c() of unquoted column names. tidyselect compatible.

.fns

Functions to pass. Can pass a list of functions.

...

Other arguments for the passed function

by

Columns to group by

Examples

Run this code
# NOT RUN {
test_df <- data.table(
  x = c(1,1,1),
  y = c(2,2,2),
  z = c("a", "a", "b"))

test_df %>%
  mutate_across.(where(is.numeric), as.character)

test_df %>%
  mutate_across.(c(x, y), ~ .x * 2)

test_df %>%
  mutate_across.(everything(), as.character)

test_df %>%
  mutate_across.(c(x, y), list(new = ~ .x * 2,
                               another = ~ .x + 7))
# }

Run the code above in your browser using DataLab