swap_if: Swap values of two columns based on a condition

View source: R/aaa.R

swap_ifR Documentation

Swap values of two columns based on a condition

Description

Swap values of two columns based on a condition

Usage

swap_if(x, condition, ...)

Arguments

x

a tibble

condition

an expression to be evaluated in data context returning a TRUE/FALSE vector

...

the two columns bewteen which values are to be swapped in dplyr::select-like syntax

Value

a tibble with conditionally swapped start and end

Examples

x <- tibble::tibble(start = c(10, 100), end = c(30, 50))
# ensure start of a range is always smaller than the end
swap_if(x, start > end, start, end)

gggenomes documentation built on Sept. 11, 2024, 8:55 p.m.