Learn R Programming

timefully (version 0.1.0)

adapt_timeseries: Adapt time-series dataframe to timezone, date range and fill gaps

Description

This function adapts the date range of a time series by reusing historical patterns based on the same weekday occurrence within the year and decimal hour of the day. It also can fill gaps in the data based on past data, so it is recommended to use it for time series with weekly or yearly patterns (so for example energy demand but not solar generation). It can also adapt the timezone of the time series, for example if the data was stored in UTC but corresponds to a different timezone.

Usage

adapt_timeseries(dtf, start_date, end_date, tzone = NULL, fill_gaps = FALSE)

Value

tibble

Arguments

dtf

data.frame or tibble, first column of name datetime being of class datetime and rest of columns being numeric

start_date

Date, start date of the output datetime sequence

end_date

Date, end date of the output datetime sequence (included)

tzone

character, desired time-zone of the datetime sequence. If NULL, the timezone of dtf$datetime is kept.

fill_gaps

boolean, whether to fill gaps based on same weekday and hour from past data (See fill_from_past function).

Examples

Run this code
# Example data set
print(dtf)

# Original date range
range(dtf$datetime)

dtf2 <- adapt_timeseries(
  dtf,
  start_date = as.Date("2021-01-01"),
  end_date = as.Date("2021-01-31"),
  tzone = "America/New_York",
  fill_gaps = FALSE
)

# New date range
range(dtf2$datetime)

Run the code above in your browser using DataLab