mutate_f: Create or transform variables, with support for multiple...

View source: R/func_mult.R

mutate_fR Documentation

Create or transform variables, with support for multiple assignment

Description

A function to create new variable(s) based on existing ones.

Usage

mutate_f(.data, ...)

## S3 method for class 'data.table'
mutate_f(.data, ...)

## S3 method for class 'tbl'
mutate_f(.data, ...)

## S3 method for class 'grouped_df'
mutate_f(.data, ...)

## S3 method for class 'data.frame'
mutate_f(.data, ...)

Arguments

.data

A data.frame, data.table, or tbl

...

Name-value pairs of expressions, following data.table syntax: "new_col" := expression. Multiple assignments can be done via c("new_col1", "new_col2") := expression_returning_a_list.

If unnamed, names of each list elements will be used

Value

a data.frame, data.table, or a tbl

Examples

df <- data.frame(baz = 1:10, foo = c(rep(1, 5), rep(2, 5)))
df %>%
   dplyr::group_by(foo) %>%
   mutate_f(c('foo', 'bar') := list(a = cumsum(baz), b = baz*2))

oucru-biostats/C306 documentation built on July 16, 2024, 2:33 p.m.