camr_limits_for_interpolation: Function to Find Limits for Interpolation

View source: R/R05-Statistical_tools.R

camr_limits_for_interpolationR Documentation

Function to Find Limits for Interpolation

Description

A function that, given a vector of x and y values, identifies the lower and upper bounds to use for linear interpolation.

Usage

camr_limits_for_interpolation(
  value,
  x,
  y,
  interp_y = TRUE,
  use_first_last = FALSE,
  warn_if_first_last = TRUE
)

Arguments

value

The x or y-axis value to interpolate.

x

A vector of numeric values for the x-axis (must match y in length).

y

A vector of numeric values for the y-axis (must match x in length).

interp_y

Logical; if TRUE, the value to interpolate is assumed to be a y coordinate.

use_first_last

Logical; if TRUE when values fall outside the provided vectors the function uses the first or last set of x and y values as an approximation.

warn_if_first_last

Logical; if TRUE warns the user when an approximation is used for cases that fall outside the range of the provided vectors.

Value

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.

Author(s)

Kevin Potter

Examples

# 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 )


rettopnivek/camrprojects documentation built on March 26, 2024, 9:17 a.m.