View source: R/R05-Statistical_tools.R
camr_limits_for_interpolation | R Documentation |
A function that, given a vector of x and y values, identifies the lower and upper bounds to use for linear interpolation.
camr_limits_for_interpolation(
value,
x,
y,
interp_y = TRUE,
use_first_last = FALSE,
warn_if_first_last = TRUE
)
value |
The x or y-axis value to interpolate. |
x |
A vector of numeric values for the x-axis
(must match |
y |
A vector of numeric values for the y-axis
(must match |
interp_y |
Logical; if |
use_first_last |
Logical; if |
warn_if_first_last |
Logical; if |
A vector of 5 values, the lower x and y-axis values
followed by the upper x and y-axis values that bracket the
point to interpolate. If there are no coordinates bracketting
the specified coordinate, a vector of NA
values is returned.
Kevin Potter
# Example curve
x = 0:5
y = c( 0, .5, 2, 4, 8, 16 )
# Value between x-axis values 2 and 3
inp = camr_limits_for_interpolation( 2.5, x, y )
camr_linear_interpolation( inp )
# Interpolate x-axis value
inp = camr_limits_for_interpolation( 3, x, y, interp_y = F )
camr_linear_interpolation( inp, interp_y = F )
# Value at an existing point
inp = camr_limits_for_interpolation( 3, x, y )
camr_linear_interpolation( inp )
# Value out of range
inp = camr_limits_for_interpolation( 6, x, y )
camr_linear_interpolation( inp )
# Approximation with first/last value (use with caution)
inp = camr_limits_for_interpolation( 6, x, y, use_first_last = T )
camr_linear_interpolation( inp )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.