
Create a tibble-like tsd
(time-series data) object from observed data and corresponding dates.
Source: R/to_time_series.R
to_time_series.Rd
This function takes observations and the corresponding date vector and converts it into a tsd
object, which is
a time series data structure that can be used for time series analysis.
Usage
to_time_series(observation, time, time_interval = c("day", "week", "month"))
Value
A tsd
object containing:
'time': The time point for for when the observation is observed.
'observation': The observed value at the time point.
Examples
# Create a `tsd` object from daily data
daily_tsd <- to_time_series(
observation = c(10, 15, 20, 18),
time = as.Date(
c("2023-01-01", "2023-01-02", "2023-01-03", "2023-01-04")
),
time_interval = "day"
)
# Create a `tsd` object from weekly data
weekly_tsd <- to_time_series(
observation = c(100, 120, 130),
time = as.Date(
c("2023-01-01", "2023-01-08", "2023-01-15")
),
time_interval = "week"
)
# Create a `tsd` object from monthly data
monthly_tsd <- to_time_series(
observation = c(500, 520, 540),
time = as.Date(
c("2023-01-01", "2023-02-01", "2023-03-01")
),
time_interval = "month"
)