tsl_handle_NA function

Handle NA Cases in Time Series Lists

Handle NA Cases in Time Series Lists

Removes or imputes NA cases in time series lists. Imputation is done via interpolation against time via zoo::na.approx(), and if there are still leading or trailing NA cases after NA interpolation, then zoo::na.spline() is applied as well to fill these gaps. Interpolated values are forced to fall within the observed data range.

This function supports a parallelization setup via future::plan(), and progress bars provided by the package progressr.

tsl_handle_NA(tsl = NULL, na_action = c("impute", "omit")) tsl_Inf_to_NA(tsl = NULL) tsl_NaN_to_NA(tsl = NULL)

Arguments

  • tsl: (required, list) Time series list. Default: NULL

  • na_action: (required, character) NA handling action. Available options are:

    • "impute" (default): NA cases are interpolated from neighbors as a function of time (see zoo::na.approx() and zoo::na.spline()).
    • "omit": rows with NA cases are removed.

Returns

time series list

Examples

#tsl with NA cases tsl <- tsl_simulate( na_fraction = 0.25 ) tsl_count_NA(tsl = tsl) if(interactive()){ #issues warning tsl_plot(tsl = tsl) } #omit NA (default) #-------------------------------------- #original row count tsl_nrow(tsl = tsl) #remove rows with NA tsl_no_na <- tsl_handle_NA( tsl = tsl, na_action = "omit" ) #count rows again #large data loss in this case! tsl_nrow(tsl = tsl_no_na) #count NA again tsl_count_NA(tsl = tsl_no_na) if(interactive()){ tsl_plot(tsl = tsl_no_na) } #impute NA with zoo::na.approx #-------------------------------------- #impute NA cases tsl_no_na <- tsl_handle_NA( tsl = tsl, na_action = "impute" ) #count rows again #large data loss in this case! tsl_nrow(tsl = tsl_no_na) if(interactive()){ tsl_plot(tsl = tsl_no_na) }

See Also

Other tsl_management: tsl_burst(), tsl_colnames_clean(), tsl_colnames_get(), tsl_colnames_prefix(), tsl_colnames_set(), tsl_colnames_suffix(), tsl_count_NA(), tsl_diagnose(), tsl_join(), tsl_names_clean(), tsl_names_get(), tsl_names_set(), tsl_names_test(), tsl_ncol(), tsl_nrow(), tsl_repair(), tsl_subset(), tsl_time(), tsl_to_df()

  • Maintainer: Blas M. Benito
  • License: MIT + file LICENSE
  • Last published: 2025-02-01