splice_series: Splice together two time series objects.

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Function to splice two vectors, covering different, but overlapping periods, into a single consistent time series.

Usage

1

Arguments

x

Original (base) time series.

y

Splicing time series, to be applied to the base time series.

base.period

Integer object comprising the base period observation. See Details for more detail explanation about the appropriate format of base.period.

direction

One of either 'after' (default) or 'before'.

Details

The function splices together two time series objects, by applying indexed movements in series y to base series x. Both objects must be of the same frequency (i.e. annual, quarterly, monthly, etc.). The function also allows for splicing 'forward' (Default)—i.e. extending an existing series beyond the base period—and 'backward'—i.e. splicing values onto the start of a series using the

For plain (non-time series) vectors, base.period must be a two-element integer vector identifying the base period observation index for x and y, respectively. For time series (ts) objects, base.period , must be a two element vector specifying the year and year-part (e.g. c(1994, 2) for the second quarter 1994. For extensible time series objects (xts), base.period must be a time-based class—one of 'Date', 'POSIXct', 'timeDate', 'yearmon' or 'yearqtr', and match the time-based index class of series x, and be within the range of x and y.

Value

An object of the same class as object x.

Author(s)

David Mitchell <david.p.mitchell@homemail.com.au>

See Also

Other R implementations to splice time series include: splice

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
  ## Non-time series (default) method example
  A <- c(100, 95, 125, 150,  NA,  NA,  NA,  NA);
  B <- c(NA,  NA,  NA, 100, 120, 150, 200, 225);
  splice_series(A, B, base.period=c(4,4));
  splice_series(B, A, base.period=c(4,4), direction="before");

  ## Time series (ts) object method example
  A <- ts(c(100, 95, 125, 150,  NA,  NA,  NA,  NA), start=1991, frequency=1);
  B <- ts(c(NA,  NA,  NA, 100, 120, 150, 200, 225), start=1991, frequency=1);
  splice_series(A, B, base.period=c(1994,1));
  splice_series(B, A, base.period=c(1994,1), direction="before");

  ## Extensible time series (xts) object method example
  A <- xts(x=c(100, 95, 125, 150,  NA,  NA,  NA,  NA),
           order.by=seq(as.Date("1991-03-01"), by="quarter", length.out=8));
  B <- xts(x=c(NA,  NA,  NA, 100, 120, 150, 200, 225),
           order.by=seq(as.Date("1991-03-01"), by="quarter", length.out=8));
  splice_series(A, B, base.period=as.Date("1994-03-01"));
  splice_series(B, A, base.period=as.Date("1994-03-01"), direction="before");

mitcda/predict.utils documentation built on May 15, 2019, 4:27 p.m.