get_value: Get a value from function defined by points

Description Usage Arguments Value Author(s) Examples

View source: R/get_value.R

Description

For a function defined by points and then interpolated as constant or linear function get a value for specific x. Function points should be provided in data frame with 2 columns: x and y values.

Usage

1
get_value(df, x_value, method = "constant")

Arguments

df

Data frame with two columns, first column representing x values and second y values.

x_value

Value for which we want to calculate this function.

method

('constant', 'linear') Should function be step function (constant between points), or interpolated linearly.

Value

Value at x_value point.

Author(s)

Elio Bartoš

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
library(tibble) #For tribble

df = tribble(
~x, ~y,
 1, 1,
 5, 5,
 10, 10
)

get_value(df, 2)           # returns 1
get_value(df, 2, "linear") # returns 2
get_value(df, 7)           # returns 5
get_value(df, 7, "linear") # returns 7

eliobartos/misc documentation built on Oct. 8, 2021, 1:10 a.m.