to_time_series: Create a tibble-like 'tsd' (time-series data) object from...

View source: R/to_time_series.R

to_time_seriesR Documentation

Create a tibble-like tsd (time-series data) object from observed data and corresponding dates.

Description

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"))

Arguments

observation

A numeric vector containing the observations.

time

A date vector containing the corresponding dates.

time_interval

A character vector specifying the time interval. Choose between 'day', 'week', or '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"
)


aedseo documentation built on April 12, 2025, 1:35 a.m.