View source: R/R05-Statistical_tools.R
camr_linear_interpolation | R Documentation |
Given a pair of x and y values, uses linear interpolation to compute a new x or y value.
camr_linear_interpolation(vec, interp_y = TRUE)
vec |
A vector of 5 values, consisting of...
A named vector can be provided, otherwise the order is assumed to follow the list given above. |
interp_y |
Logical; if |
The interpolated x or y value. If outside the lower or upper
boundaries, NA
is returned instead.
Kevin Potter
# Linear interpolation for y
inp <- c( x0 = 0, y0 = 0, x1 = 1, y1 = 2, x = .5 )
camr_linear_interpolation( inp )
# Linear interpolation for x
inp <- c( x0 = 0, y0 = 0, x1 = 1, y1 = 2, y = .5 )
camr_linear_interpolation( inp, FALSE )
# Linear interpolation across multiple values
x = c( 0, 1, 2 )
y = c( 0, 2, 4 )
# Create matrix with 5th column for points to interpolate at
m = cbind( x[-3], y[-3], x[-1], y[-1], c( .5, 1.5 ) )
# Linear interpolation for y values
apply( m, 1, camr_linear_interpolation )
# Linear interpolation for x values (NA for value outside boundary)
apply( m, 1, camr_linear_interpolation, interp_y = FALSE )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.