mutate_rows: Extension of 'mutate' by a predicate function

View source: R/mutate.R

mutate_rowsR Documentation

Extension of mutate by a predicate function

Description

Use a predicate function .p to mutate only a subset of rows where the predicate is satisfied. Creating new columns in combination with a predicate creates by default NA values in rows where the predicate is not satisfied.

Usage

mutate_rows(.df, .p, .ignore_na = FALSE, ...)

Arguments

.df

A tibble.

.p

A predicate function.

.ignore_na

Should NA values in the evaluation of the predicate function be ignored? Defaults to FALSE.

...

Name-value pairs passed to mutate.

Value

A tibble.

Examples

mutate_rows(
  tibble::tibble(
    x = c(-1, 0, -1),
    y = c(1, 1, 1)
  ),
  x < 0,
  y = y + 1,
  z = y + 1
)

albutz/tidyhelpr documentation built on May 9, 2022, 12:03 a.m.