Learn R Programming

fb4package (version 2.0.0)

interpolate_time_series: Interpolate time series with error handling

Description

Interpolate time series with error handling

Usage

interpolate_time_series(
  data,
  value_columns,
  target_days,
  method = "linear",
  fill_na_method = "extend",
  validate_input = TRUE
)

Value

A data.frame with one row per element of target_days. The first column is Day (integer). Subsequent columns correspond to value_columns, each containing the interpolated numeric values at the requested days. NA values are resolved according to

fill_na_method: "extend" fills with the nearest valid value, "zero" replaces with 0, and "mean" uses the column mean.

Arguments

data

Data frame with Day column and value columns

value_columns

Vector with names of columns to interpolate

target_days

Vector of target days

method

Interpolation method ("linear", "constant", "spline")

fill_na_method

Method to fill missing values ("extend", "zero", "mean")

validate_input

Validate input structure, default TRUE

Examples

Run this code
temp_data <- data.frame(Day = c(1, 100, 200, 365),
                        Temperature = c(5, 15, 18, 7))
interpolate_time_series(temp_data, value_columns = "Temperature",
                        target_days = 1:365)

Run the code above in your browser using DataLab