interpolate | R Documentation |
Interpolate to dimensions missing in a data.table, between dimensions which exist. Uses linear interpolation.
interpolate(dt, id_cols, interpolate_col, value_col, interpolate_vals, ...)
dt |
[ |
id_cols |
[ |
interpolate_col |
[ |
value_col |
[ |
interpolate_vals |
[ |
... |
Other arguments to be passed to |
This function uses stats::approx
to solve a linear interpolation.
Values outside the bounds of known data will be returned as NA. Use
extrapolate()
to get values outside of the bounds of the data.
Consider log transforming your data prior to interpolation if
appropriate.
[data.table()
] dt
with added rows for interpolated values.
dt <- data.table::data.table(
group = c(rep("a", 5), rep("b", 5)),
x = c(1, 3, 4, 5, 10, 1, 2, 6, 8, 10),
y = c(10, 30, 40, 50, 100, 10, 20, 60, 80, 100)
)
dt <- interpolate(dt, id_cols = c("group", "x"), interpolate_col = "x",
value_col = "y", interpolate_vals = c(1:10))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.