Learn R Programming

datana (version 1.1.5)

interp: Interpolation function

Description

Interpolation function

Usage

interp(
  x,
  y,
  xlu = NA,
  ylu = NA,
  arrange = y,
  asc = TRUE,
  completename.x = "xlu",
  completename.y = "ylu",
  overwrite = FALSE
)

Arguments

x

vector of x values, should have same length as y.

y

vector of y values, should have same length as x.

xlu

vector of new x values given to interpolate corresponding y values.

ylu

vector of new y values given to interpolate corresponding x values.

arrange

sort data based on x or y values

asc

wether to sort ascending (TRUE, default) or descending (FALSE).

completename.x

name to use for the completevals xlu generated columns.

completename.y

name to use for the completevals ylu generated columns.

overwrite

wether to overwrite original values (TRUE) or not (FALSE, default) if given interpolation points exists in the original data.

Author

Christian Salas-Eljatib and Nicolás Campos

Details

This function interpolate via spline missing values in a two dimensional array, where one column ascends while the other descends in value.

Examples

Run this code
##- example data
my.x <- seq(40, 0, -4)
my.x

my.y <- seq(0, 20, 2)
my.y

myData <- data.frame(x = my.x, y = my.y)
myData

##- example `xlu'
my.xlu <- c(11, 15, 25)

##- example `ylu'
my.ylu <- c(15, 5, 9) # note that values can be unordered

##- interpolation
new.y <- interp(x = my.x, y = my.y, xlu = my.xlu) # interp missing ylu
new.y$intvalues # interpolated rows
new.y$datares # interpolated rows appended to original dataframe
new.y$completevals

new.x <- interp(x = my.x, y = my.y, ylu = my.ylu) # interp missing xlu
new.x$intvalues # interpolated rows
new.x$datares # interpolated rows appended to original dataframe
new.x$completevals

##- both interpolation at the same time
interp(x = my.x, y = my.y, xlu = my.xlu, ylu = my.ylu,
       arrange = my.y, asc = TRUE)

interp(x = my.x, y = my.y, xlu = my.xlu, ylu = my.ylu,
       arrange = my.x, asc = TRUE, completename.x = "dlu")

##- when overwrite = TRUE a warning is noted
interp(x = my.x, y = my.y, ylu = c(14,11), overwrite = TRUE)
interp(x = my.x, y = my.y, xlu = c(28, 15), overwrite = TRUE)
interp(x = my.x, y = my.y, xlu = c(28, 15), ylu = c(14,11), overwrite = TRUE)

Run the code above in your browser using DataLab