File: methods-as.Rd

package info (click to toggle)
r-cran-timeseries 4041.111-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,704 kB
  • sloc: makefile: 14
file content (137 lines) | stat: -rw-r--r-- 3,578 bytes parent folder | download
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
\name{as}
\alias{as}

\alias{as.timeSeries}
\alias{as.timeSeries.default}
\alias{as.timeSeries.data.frame} 
\alias{as.timeSeries.character}
\alias{as.timeSeries.ts} 
\alias{as.timeSeries.zoo} 

\alias{as.matrix,timeSeries-method}
\alias{as.data.frame,timeSeries-method}
\alias{as.list,timeSeries-method}
%\alias{as.ts,timeSeries-method}

% S3 versions of the above
\alias{as.matrix.timeSeries}
\alias{as.data.frame.timeSeries}
\alias{as.list.timeSeries}


\alias{as.ts}
\alias{as.ts.timeSeries}

% for as(x, "class") where x is the 1st element of the signature
\alias{coerce,ANY,timeSeries-method}
\alias{coerce,data.frame,timeSeries-method}
\alias{coerce,character,timeSeries-method}
\alias{coerce,ts,timeSeries-method}

% for as(x, "class") where x is timeSeries
\alias{coerce,timeSeries,matrix-method}
\alias{coerce,timeSeries,data.frame-method}
\alias{coerce,timeSeries,list-method}
\alias{coerce,timeSeries,ts-method}
\alias{coerce,timeSeries,tse-method}



\title{Convert objects to/from class 'timeSeries'}

\description{
  
  Functions and methods dealing with the coercion between \code{"timeSeries"}
  and other classes.

}


\usage{
## convert to 'timeSeries'
as.timeSeries(x, \dots)

## convert from 'timeSeries' to other classes
\method{as.ts}{timeSeries}(x, \dots)
\S4method{as.matrix}{timeSeries}(x, \dots)
\S4method{as.data.frame}{timeSeries}(x, row.names = NULL, optional = FALSE, \dots)
\S4method{as.list}{timeSeries}(x, \dots)
}


\arguments{

    \item{x}{ 
        the object to be converted, see Section \sQuote{Details} for the
        special case when \code{class(x)} is \code{"character"}.
    } 
    \item{row.names}{
        \code{NULL} or a character vector giving the row names for the
        data frame. Missing values are not allowed.
    }
    \item{optional}{
        a logical value. If \code{TRUE}, setting row names and converting
        column names (to syntactic names) is optional.
    }
    \item{\dots}{
        arguments passed to other methods.
    }
  
}

\details{
    
  Functions to create \code{"timeSeries"} objects from other objects and
  to convert \code{"timeSeries"} objects to other classes.

  \code{as.timeSeries} is a generic function to convert an object to
  \code{"timeSeries"}.  There are specialised methods for the following
  classes: \code{"ts"}, \code{"data.frame"}, \code{"character"}, and
  \code{"zoo"}. The default method is equivalent to calling
  \code{"timeSeries()"}, so \code{x} can be of any type that
  \code{"timeSeries()"} accepts.
  
  The \code{character} method of \code{as.timeSeries} is special, in
  that its contents are parsed and evaluated, then \code{as.timeSeries}
  is called on the returned value (passing also the \code{"..."}
  arguments. Care is needed to avoid infinite recursion here since
  currently the code doesn't guard against it.
  
}

\value{
    
  for \code{as.timeSeries}, an object of class \code{"timeSeries"}. \cr
    
  for \code{as.numeric}, \code{as.data.frame}, \code{as.matrix},
  \code{as.ts}, \code{as.list} -  a numeric vector, a data frame, a
  matrix, an object of class \code{ts}, or a \code{"list"},
  respectively.
  
}

\seealso{
  \code{\link{timeSeries}},
  class \code{\linkS4class{timeSeries}}
}

\examples{
## 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)
}

\keyword{chron}
\keyword{ts}