swap()
swaps values between two columns. swap_if()
swaps values only in rows where a condition is met. x
and y
will be cast to a common type using vctrs::vec_cast_common()
.
Usage
swap(.data, x, y)
swap_if(.data, cond, x, y, missing = c("NA", "keep", "swap"))
References
Based on Hadley's code in a this dplyr GitHub issue.