approxMap | R Documentation |
Define a function that generates an approximation function for a given subset of data. This is designed to be used to predict values in one data.table using values in another via the j slot. See examples.
approxMap(
dt,
id.val,
x = "x",
y = "y",
id.col = "ID",
rand.val = NULL,
rand.range = c(0, 1),
FUN = stats::approxfun,
...
)
dt |
A data.table containing the observed data |
id.val |
The value to look up in |
x |
A character string representing the name of the independent variable
column in |
y |
A character string representing the name of the dependent variable
column in |
id.col |
A character string representing the name of the group column in
|
rand.val |
A character vector with values present in |
rand.range |
A vector of two numbers repretenting t he range of
potential values for |
FUN |
The approximation function. Default is |
... |
Additional parameters to pass to |
# Generate a data.table with different observations for different categories
data <- data.table(ID = rep(c("A","B","C"), each = 10),
x = runif(30),
y = runif(30, min = 10, max = 20))
# Create a target data.table
target <- data.table(ID = rep(c("A","B","C"), each = 101),
x = rep(seq(0,1,length.out=101), each = 3))
target[, y := approxMap(data, id.val = ID, rule = 2, na.rm=TRUE)(x),by='ID']
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.