math | R Documentation |
Functions and methods for mathematical operations on "timeSeries"
.
## S4 method for signature 'timeSeries,timeSeries'
Ops(e1, e2)
## S4 method for signature 'timeSeries'
Math(x)
## S4 method for signature 'timeSeries'
Math2(x, digits)
## S3 method for class 'timeSeries'
quantile(x, ...)
## S3 method for class 'timeSeries'
median(x, na.rm = FALSE, ...)
x |
an object of class |
digits |
number of digits to be used in 'round' or 'signif'. |
e1 , e2 |
at least one of the two objects is from class |
na.rm |
a logical value: should missing values be removed? |
... |
arguments to be passed. |
The methods for the Math
and Math2
groups of
mathematical functions return 'timeSeries' objects. Most of them work
element-wise on the data part of the time series with the exception of
cummin
, cummax
, cumsum
, and cumprod
which
work columnwise.
The Ops
group includes mathematical operators. For the binary
operators methods are defined for pairs of at least one 'timeSeries'
object. These work as expected on the data parts of the arguments.
If the operation gives a value of the same dimension as the data part
of the 'timeSeries' object, it replaces the original data in the
object.
There are also methods for quantile
and median
.
the value from a mathematical or logical operation operating on
objects of class "timeSeries"
or the value computed by a
mathematical function.
colCumXXX
## create an artificial 'timeSeries' object
setRmetricsOptions(myFinCenter = "GMT")
charvec = timeCalendar()
set.seed(4711)
data = matrix(exp(cumsum(rnorm(12, sd = 0.1))))
TS = timeSeries(data, charvec, units = "TS")
TS
## mathematical operations: | +/- * ^ ...
TS^2
TS[2:4]
OR = returns(TS)
OR
OR > 0
## median, quantile
median(TS)
quantile(TS)
TS[3] <- NA # to demonstrate 'na.rm'
median(TS) # NA
#quantile(TS) # error
median(TS, na.rm = TRUE)
quantile(TS, na.rm = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.