Skip to contents

Wraps stats::ts() with explicit validation: the input must be a strictly ordered, regular numeric series with no implicit missing periods. This is the single pre-processing routine through which all subsequent functions receive their data, so time attributes are maintained uniformly.

Usage

morie_ts(
  x,
  frequency = 1,
  start = 1,
  calendar = NA_character_,
  na_action = c("error", "interpolate", "omit"),
  units = attr(x, "units")
)

Arguments

x

A numeric vector (or an object coercible to one, including a units-typed vector, which is coerced via [as.numeric()]), or an existing ts.

frequency

Number of observations per unit of time (e.g. 12 for monthly-in-years). Default 1.

start

Time of the first observation. Default 1.

calendar

Character tag documenting the calendar system assumed (e.g. "monthly"); recorded as an attribute, not interpreted.

na_action

How to handle missing values (regular series require an explicit decision): "error" (default) rejects implicit missing values; "interpolate" fills them by linear interpolation (imputation); "omit" drops them with a warning (the series is then treated as irregular).

units

Optional character unit label carried as an attribute and propagated to return values.

Value

A morie_ts object (a ts with validated ordering).

Examples

set.seed(1)
morie_ts(cumsum(rnorm(24)), frequency = 12, start = 2000)
#>             Jan        Feb        Mar        Apr        May        Jun
#> 2000 -0.6264538 -0.4428105 -1.2784391  0.3168417  0.6463495 -0.1741189
#> 2001  2.6024116  0.3877118  1.5126427  1.4677091  1.4515188  2.3953550
#>             Jul        Aug        Sep        Oct        Nov        Dec
#> 2000  0.3133101  1.0516348  1.6274162  1.3220278  2.8338090  3.2236522
#> 2001  3.2165762  3.8104775  4.7294549  5.5115912  5.5861562  3.5968045