as.uts_vector: Coercion to uts_vector

Description Usage Arguments Value Methods (by class) See Also Examples

Description

Convert univariate and multivariate time series objects from other R packages to "uts_vector" objects.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
as.uts_vector(x, ...)

## S3 method for class 'ts'
as.uts_vector(x, ...)

## S3 method for class 'fts'
as.uts_vector(x, ...)

## S3 method for class 'irts'
as.uts_vector(x, ...)

## S3 method for class 'xts'
as.uts_vector(x, ...)

## S3 method for class 'zoo'
as.uts_vector(x, ...)

Arguments

x

a time series object of appropriate type.

...

further arguments passed to or from methods.

Value

An object of class "uts_vector".

Methods (by class)

See Also

as.uts for converting just univariate time series.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Convert a bivariate "ts"
ts1 <- ts(matrix(1:20, 10, 2), start=c(2016, 1), frequency=12, names=c("apples", "oranges"))
utsv <- as.uts_vector(ts1)
utsv[[1]]
utsv$oranges

# Convert a 2-dimensional "fts" and remove NA observations
if (requireNamespace("fts", quietly = TRUE)) {
  x <- fts::fts(index=seq(from=Sys.Date(), by="months", length.out=24),data=1:24)
  y <- fts::fts(index=seq(from=Sys.Date(), by="months", length.out=12),data=13:24)
  fts1 <- cbind(x, y)
  na.omit(as.uts_vector(fts1))
}

# Convert a 3-dimensional "irts"
if (requireNamespace("tseries", quietly = TRUE)) {
  irts1 <- tseries::irts(as.POSIXct("2015-01-01") + days(c(1, 3, 7, 9)), matrix(1:12, 4))
  as.uts_vector(irts1)
}

# Convert a 3-dimensional "xts"
if (requireNamespace("zoo", quietly = TRUE)) {
  xts1 <- xts::xts(matrix(1:12, 4, 3), as.Date("2003-01-01") + 0:3)
  as.uts_vector(xts1)
}

# Convert a 3-dimensional "zoo"
if (requireNamespace("zoo", quietly = TRUE)) {
  zoo1 <- zoo::zoo(matrix(1:12, 4, 3), as.Date("2003-01-01") + 0:3)
  utsv <- as.uts_vector(zoo1)
  utsv[[1]]
}

andreas50/utsMultivariate documentation built on May 12, 2019, 10:31 p.m.