splitMerge: Apply a function to a subset of a data.frame

View source: R/splitMerge.R

splitMergeR Documentation

Apply a function to a subset of a data.frame

Description

Subset a data.frame according to a condition, apply a function to the rows where the condition is TRUE, then rejoin with the rows where condition is FALSE or NA. A split-apply-combine where function is only applied to a subset of rows.

Filtering expression can be either quoted or unquoted, e.g. complete.cases(x, y) (where x and y are column names) or "complete.cases(x, y)". To filter with multiple conditions use "&", e.g. "x == 1 & y == 2"

Usage

splitMerge(df, ex, f, verbose = TRUE, ...)

Arguments

df

A data.frame or tibble

ex

character(1) An character expression for filtering df using dplyr::filter, e.g. 'grepl("X", colname)'

f

A function to apply to the rows where ex is TRUE and returns a data.frame

verbose

Should a warning be issued if extra rows are added after applying f? (Default: TRUE)

...

Extra arguments for f

Value

df where function f has been applied only to the rows where ex is TRUE


HelenLindsay/AbNames documentation built on June 6, 2023, 1:18 p.m.