Learn R Programming

timeSeries (version 3062.100)

as: timeSeries Class, Coercion and Transformation

Description

Functions and methods dealing with the coercion of 'timeSeries' objects.

Usage

# S3 method for default
as.timeSeries(x, ...)
# S3 method for ts
as.timeSeries(x, ...) 
# S3 method for data.frame
as.timeSeries(x, ...) 
# S3 method for character
as.timeSeries(x, ...) 
# S3 method for zoo
as.timeSeries(x, ...) 

# S4 method for timeSeries as.matrix(x, ...) # S4 method for timeSeries as.ts(x, ...) # S4 method for timeSeries as.data.frame(x, row.names = NULL, optional = FALSE, ...) # S4 method for timeSeries as.ts(x, ...)

Value

Function as.timeSeries

returns a S4 object of class 'timeSeries'.

Functions as.numeric,

as.data.frame,

as.matrix,

as.ts

return depending on the generic function a numeric vector, a data frame, a matrix, or an object of class ts.

Arguments

optional

A logical value. If TRUE, setting row names and converting column names (to syntactic names) is optional.

row.names

NULL or a character vector giving the row names for the data frame. Missing values are not allowed.

x

an object which is coerced according to the generic function.

...

arguments passed to other methods.

Details

Functions to create 'timeSeries' objects from other objects:

as.timeSeriesGeneric to convert an object to a 'timeSeries',
as.timeSeries.defaultReturns the unchanged object,
as.timeSeries.numericConverts from a numeric vector,
as.timeSseries.data.frameConverts from a numeric vector,
as.timeSeries.matrixConverts from a matrix,
as.timeSeries.tsConverts from an object of class 'ts',
as.timeSeries.characterConverts from a named demo file,
as.timeSeries.zooConverts an object of class zoo.

Functions to transform 'timeSeries' objects into other objects:

as.matrix.timeSeriesCoerces a 'timeSeries' to a matrix,
as.data.frame.timeSeriesCoerces a 'timeSeries' to a data.frame,
as.ts.timeSeriesS3: Coerces a 'timeSeries' to a 'ts' object.
as.ts.timeSeriesS3: Coerces a 'timeSeries' to a 'logical' object.

Examples

Run this code
## Create an Artificial timeSeries Object - 
   setRmetricsOptions(myFinCenter = "GMT")
   charvec <- timeCalendar()
   data <- matrix(rnorm(12))
   TS <- timeSeries(data, charvec, units = "RAND")
   TS

## Coerce to Vector - 
   as.vector(TS)
   
## Coerce to Matrix - 
   as.matrix(TS)
  
## Coerce to Data Frame - 
   as.data.frame(TS)

Run the code above in your browser using DataLab