df_to_reg_ts {tstools}R Documentation

Turn data.frame to Regular Monthly or Quarterly Time Series

Description

Turn a data.frame with date columns to a regular time series object if possible. Design to work with quarterly and monthly data.

Usage

df_to_reg_ts(
  dframe,
  var_cols,
  year_col = "year",
  period_col = "month",
  freq = 12,
  return_ts = T,
  by = NULL
)

Arguments

dframe

data.frame input

var_cols

columns that contain variables as opposed to date index.

year_col

integer, logical or character vector indicating the year position within the data.frame.

period_col

integer, logical or character vector indicating the period position within the data.frame.

freq

integer indicating the frequency of new time series.

return_ts

logical should a (list of) time series be returned? Defaults to TRUE. FALSE returns data.frame.

by

character overwrite automatically detected (from freq) by parameter. e.g. '1 day'. Defaults to NULL.

Examples

start_m <- as.Date("2017-01-01")
df_missing <- data.frame(
  date = seq(start_m, by = "2 months", length = 6),
  value = 1:6,
  another_value = letters[1:6],
  yet_another_col = letters[6:1]
)
df_to_reg_ts(df_missing, c("value", "another_value"))
df_to_reg_ts(df_missing, c("value", "another_value"), return_ts = FALSE)

[Package tstools version 0.4.3 Index]