Skip to contents

Mirrors the C# OrderedPairedData.GetYFromX/GetXFromY: linear interpolation over a curve that keeps itself sorted/validated against a caller-chosen monotonicity contract, with optional per-axis transforms (log10 or the standard normal z-score) applied before/after interpolation. Exactly one of xout/yout must be supplied.

Usage

curve_interpolate(
  x,
  y,
  xout = NULL,
  yout = NULL,
  x_transform = "none",
  y_transform = "none",
  order_x = "ascending",
  order_y = "ascending",
  strict_x = TRUE,
  strict_y = TRUE
)

Arguments

x, y

numeric vectors of equal length (at least two), the curve's ordinates.

xout

numeric vector of x positions to interpolate y at.

yout

numeric vector of y positions to interpolate x at.

x_transform, y_transform

one of "none" (default), "logarithmic" (also accepted as "log"), or "normal_z".

order_x, order_y

one of "ascending" (default), "descending", or "none".

strict_x, strict_y

require x/y to strictly increase/decrease (per order_x/order_y) between consecutive ordinates. Default TRUE.

Value

a numeric vector, the same length as whichever of xout/yout was supplied.

Examples

curve_interpolate(c(50, 100, 150, 200, 250), c(100, 200, 300, 400, 500), xout = 75)
#> [1] 150