add_hf_lags.Rd
Add high frequency lags to low frequency tsibble
add_hf_lags(lf_data, hf_data, hf_variable = NULL, n_lags = 1, one_row = TRUE)
lf_data | low frequency data |
---|---|
hf_data | high frequency data |
hf_variable | names of high frequency time series, all by default |
n_lags | number of lags to add |
one_row | output representation |
tsibble with high frequency lags added
Adds high frequency lags to low frequency tsibble. The function concatenates n_lags of hf_data to lf_data. The concatenated observations from hf_data are from the same day or earlier than the date indicated by lf_date. If one_row is TRUE the high frequency observations are put in a row so as the number of rows in the new table is equal to those of lf_data. Otherwise the lags of high-frequency data increase the number of rows and the number of rows in new table is (number of rows in lf_data)*n_lags.
hf_data <- tibble::tibble(date = lubridate::ymd("2011-01-01") + lubridate::days(0:90), observations = rnorm(91)) lf_data <- stats::ts(rnorm(4), start = c(2011, 01), frequency = 12) add_hf_lags(lf_data, hf_data, n_lags = 5)#> Warning: Incompatible methods ("<=.Date", "<=.vctrs_vctr") for "<="#> Warning: Incompatible methods ("<=.Date", "<=.vctrs_vctr") for "<="#> Warning: Incompatible methods ("<=.Date", "<=.vctrs_vctr") for "<="#> Warning: Incompatible methods ("<=.Date", "<=.vctrs_vctr") for "<="#> # A tibble: 4 x 7 #> date value observations_1 observations_2 observations_3 observations_4 #> <mth> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 2011 янв -0.397 -0.387 NA NA NA #> 2 2011 фев -0.823 0.846 -1.15 0.192 -0.528 #> 3 2011 мар -0.579 0.804 0.783 -0.356 0.0385 #> 4 2011 апр 1.76 1.12 1.14 1.06 2.56 #> # … with 1 more variable: observations_5 <dbl>