A set of simple, vectorized, pipe-friendly arithmetic functions for
transforming numeric data in pipelines. These helpers make common
operations like multiplication, division, addition, subtraction,
exponentiation, and reciprocals clearer when using the native pipe |>
.
reciprocal(x)
pow(x, p)
add(x, k)
subtract(x, k)
mult(x, k)
divide(x, k)
A numeric vector or scalar resulting from the transformation.
All functions are vectorized and support numeric vectors, scalars, or compatible objects. They are designed to improve the readability of transformation pipelines.
x <- c(1, 2, 3)
# Multiplication and division
x |> mult(10)
#> [1] 10 20 30
x |> divide(2)
#> [1] 0.5 1.0 1.5
# Addition and subtraction
x |> add(5)
#> [1] 6 7 8
x |> subtract(1)
#> [1] 0 1 2
# Reciprocal
x |> reciprocal()
#> [1] 1.0000000 0.5000000 0.3333333
# Power
x |> pow(2)
#> [1] 1 4 9
# Combined use in pipelines
x |>
mult(2) |>
add(3) |>
reciprocal()
#> [1] 0.2000000 0.1428571 0.1111111