timeDateMathOps {fCalendar}R Documentation

timeDate Mathematical Operations

Description

A collection and description of functions for mathematical and logical operations on 'timeDate' objects.

The functions are:

Ops.timeDate Group 'Ops' generic functions for 'timeDate' objects,
+.timeDate Performs arithmetic + operation on 'timeDate' objects,
-.timeDate Performs arithmetic - operation on 'timeDate' objects,
diff.timeDate Returns suitably lagged and iterated differences,
difftimeDate Returns a difference of two 'timeDate' objects,
round.timeDate Rounds objects of class 'timeDate',
trunc.timeDate Truncates objects of class 'timeDate'.

Usage

## S3 method for class 'timeDate':
Ops(e1, e2)
## S3 method for class 'timeDate':
e1 + e2
## S3 method for class 'timeDate':
e1 - e2
## S3 method for class 'timeDate':
diff(x, lag = 1, differences = 1, ...)
difftimeDate(time1, time2, 
    units = c("auto", "secs", "mins", "hours", "days", "weeks"))
## S3 method for class 'timeDate':
round(x, digits = c("days", "hours", "mins")) 
## S3 method for class 'timeDate':
trunc(x, units = c("days", "hours", "mins"), ...)     

Arguments

differences [diff] -
an integer indicating the order of the difference.
digits, units [difftimeDate][round][trunc] -
a character string denoting the date/time units in which the results are desired.
e1, e2 ["+"][["-"]["Ops"] -
usually objects of class timeDate, in the case of addition and subtraction e2 may be of class numeric.
lag [lag] -
an integer indicating which lag to use.
method [modify] -
a character string defining the modification method, one of "sort", "round", or "trunc".
time1, time2 [difftime] -
two objects objects of class timeDate.
x [diff][round][trunc] -
an object of class timeDate.
... arguments passed to other methods.

Value

Ops.timeDate
these are functions for mathematical operations. Group code{Ops} are generic functions which manage mathematical operations.
+.timeDate
-.timeDate
The plus operator "+" performs arithmetic "+" operation on timeDate objects, and the minus operator "-" returns a difftime object if both arguments e1 and e2 are "timeDate" objects, or returns a "timeDate" object e2 seconds earlier than e1.
diff.timeDate
For the function, diff.timeDate, if x is a vector of length n and differences=1, then the computed result is equal to the successive differences x[(1+lag):n] - x[1:(n-lag)]. If difference is larger than one this algorithm is applied recursively to x. Note that the returned value is a vector which is shorter than x.
difftimeDate
The function, difftimeDate, takes a difference of two timeDate objects and returns an object of class "difftime" with an attribute indicating the units.
round.timeDate
trunc.timeDate
The two functions round and trunc allow to round or to truncate "timedate" objects to the specified unit and return them as "timedate" objects. - Note, ther is an inconsistency round uses digits as argument and not units.

Author(s)

Diethelm Wuertz for the Rmetrics R-port.

See Also

We also recommend to inspect the help pages for the POSIX time and date class, ?Dates, and the help pages from the contributed R packages chron and date.

Examples

## Create Character Vectors:
   dts = c("1989-09-28", "2001-01-15", "2004-08-30", "1990-02-09")
   dts
   tms = c(  "23:12:55",   "10:34:02",   "08:30:00",   "11:18:23")
   tms
   
## "+/-" - 
   # Add One Day to a Given timeDate Object:
   GMT = timeDate(dts, zone = "GMT", FinCenter = "GMT")
   GMT
   ZUR = timeDate(dts, zone = "GMT", FinCenter = "Europe/Zurich")
   ZUR
   GMT + 24*3600
   ZUR[2] - ZUR[1]
  
## "<" ">" "==" ... - 
   # Subsets from and Lops for timeDate Objects:
   GMT[GMT < GMT[2]]
   ZUR[ZUR < ZUR[3]] == ZUR[1:3]

## diff - 
   # Suitably Lagged and Iterated Differences:
   diff(GMT)
   diff(GMT, lag = 2)
   diff(GMT, lag = 1, diff = 2)
   difftimeDate(GMT[1:2], GMT[-(1:2)])  

[Package fCalendar version 260.72 Index]