Convert objects to/from class 'timeSeries'
methods-as.Rd
Functions and methods dealing with the coercion between "timeSeries"
and other classes.
Usage
## convert to 'timeSeries'
as.timeSeries(x, ...)
## convert from 'timeSeries' to other classes
# S3 method for timeSeries
as.ts(x, ...)
# S4 method for timeSeries
as.matrix(x, ...)
# S4 method for timeSeries
as.data.frame(x, row.names = NULL, optional = FALSE, ...)
# S4 method for timeSeries
as.list(x, ...)
Arguments
- x
the object to be converted, see Section ‘Details’ for the special case when
class(x)
is"character"
.- row.names
NULL
or a character vector giving the row names for the data frame. Missing values are not allowed.- optional
a logical value. If
TRUE
, setting row names and converting column names (to syntactic names) is optional.- ...
arguments passed to other methods.
Details
Functions to create "timeSeries"
objects from other objects and
to convert "timeSeries"
objects to other classes.
as.timeSeries
is a generic function to convert an object to
"timeSeries"
. There are specialised methods for the following
classes: "ts"
, "data.frame"
, "character"
, and
"zoo"
. The default method is equivalent to calling
"timeSeries()"
, so x
can be of any type that
"timeSeries()"
accepts.
The character
method of as.timeSeries
is special, in
that its contents are parsed and evaluated, then as.timeSeries
is called on the returned value (passing also the "..."
arguments. Care is needed to avoid infinite recursion here since
currently the code doesn't guard against it.
Value
for as.timeSeries
, an object of class "timeSeries"
.
for as.numeric
, as.data.frame
, as.matrix
,
as.ts
, as.list
- a numeric vector, a data frame, a
matrix, an object of class ts
, or a "list"
,
respectively.
See also
timeSeries
,
class timeSeries
Examples
## Create an Artificial 'timeSeries' Object
setRmetricsOptions(myFinCenter = "GMT")
charvec <- timeCalendar()
data <- matrix(rnorm(12))
TS <- timeSeries(data, charvec, units = "RAND")
TS
#> GMT
#> RAND
#> 2024-01-01 -0.53462554
#> 2024-02-01 1.03171730
#> 2024-03-01 0.70956662
#> 2024-04-01 0.07844901
#> 2024-05-01 0.97608044
#> 2024-06-01 -0.26208703
#> 2024-07-01 -1.37029646
#> 2024-08-01 0.19624484
#> 2024-09-01 -1.21235565
#> 2024-10-01 -0.15885573
#> 2024-11-01 -0.66830348
#> 2024-12-01 0.88260316
## Coerce to Vector
as.vector(TS)
#> [1] -0.53462554 1.03171730 0.70956662 0.07844901 0.97608044 -0.26208703
#> [7] -1.37029646 0.19624484 -1.21235565 -0.15885573 -0.66830348 0.88260316
## Coerce to Matrix
as.matrix(TS)
#> RAND
#> 2024-01-01 -0.53462554
#> 2024-02-01 1.03171730
#> 2024-03-01 0.70956662
#> 2024-04-01 0.07844901
#> 2024-05-01 0.97608044
#> 2024-06-01 -0.26208703
#> 2024-07-01 -1.37029646
#> 2024-08-01 0.19624484
#> 2024-09-01 -1.21235565
#> 2024-10-01 -0.15885573
#> 2024-11-01 -0.66830348
#> 2024-12-01 0.88260316
## Coerce to Data Frame
as.data.frame(TS)
#> RAND
#> 2024-01-01 -0.53462554
#> 2024-02-01 1.03171730
#> 2024-03-01 0.70956662
#> 2024-04-01 0.07844901
#> 2024-05-01 0.97608044
#> 2024-06-01 -0.26208703
#> 2024-07-01 -1.37029646
#> 2024-08-01 0.19624484
#> 2024-09-01 -1.21235565
#> 2024-10-01 -0.15885573
#> 2024-11-01 -0.66830348
#> 2024-12-01 0.88260316