POSIXctp {timetools} | R Documentation |
Class "POSIXctp"
Description
Class that defines 'periods of time' objects such as 'one month', 'two months', 'three hours', 'four minutes', etc.
Usage
POSIXctp(duration, unit)
as.POSIXctp(from, ...)
## S3 method for class 'POSIXctp'
x[i, ...]
## S3 replacement method for class 'POSIXctp'
x[i] <- value
## S3 method for class 'POSIXctp'
c(...)
## S3 method for class 'POSIXctp'
split(x, f, drop=FALSE, ...)
## S3 method for class 'POSIXctp'
rep(x, ...)
## S3 method for class 'POSIXctp'
unique(x, incomparables=FALSE, ...)
## S4 method for signature 'POSIXctp'
unit(x, ...)
## S4 replacement method for signature 'POSIXctp'
unit(object) <- value
## S4 method for signature 'POSIXctp'
duration(x, ...)
## S4 method for signature 'POSIXctp'
length(x)
## S3 method for class 'POSIXctp'
print(x, ...)
## S3 method for class 'POSIXctp'
format(x, ...)
## S3 method for class 'POSIXctp'
summary(object, ...)
## S3 method for class 'POSIXctp'
head(x, ...)
## S3 method for class 'POSIXctp'
tail(x, ...)
## S4 method for signature 'POSIXctp'
show(object)
## S4 method for signature 'POSIXctp,POSIXctp'
match(x, table, nomatch = NA_integer_, incomparables=NULL)
## S4 method for signature 'POSIXctp,ANY'
match(x, table, nomatch = NA_integer_, incomparables=NULL)
## S4 method for signature 'POSIXctp,ANY'
x %in% table
## S3 method for class 'POSIXctp'
Ops(e1, e2)
## S4 method for signature 'numeric,POSIXctp'
e1 * e2
## S4 method for signature 'POSIXctp,numeric'
e1 * e2
## S4 method for signature 'POSIXctp,POSIXctp'
e1 + e2
## S4 method for signature 'POSIXctp,POSIXctp'
e1 - e2
## S4 method for signature 'POSIXct,POSIXctp'
e1 + e2
## S4 method for signature 'POSIXctp,POSIXct'
e1 + e2
## S4 method for signature 'POSIXct,POSIXctp'
e1 - e2
## S4 method for signature 'POSIXctp'
as.numeric(x, ...)
Arguments
duration |
A vector |
unit |
A vector of factors defined by |
from |
Object to convert to a period of time (actually works only for
|
x |
|
i |
index ( |
value |
New |
f |
|
drop |
Argument specific to the split method. See |
object |
|
table |
The values ( |
nomatch |
The value to be returned i nthe case when no match is found.
See |
incomparables |
A vector of values that cannot be matched.
See |
e1 |
|
e2 |
|
... |
More arguments. |
Objects from the Class
Objects of this class are used to represent periods of times such
as ‘one hour’, ‘two seconds’, ‘three years’, etc.
Partial periods of time are not allowed (‘1.5 hours’ will be coerced
to an integer value using as.integer
).
POSIXctp (‘p’ stands for‘period’) has only one unit. So ‘one hour and 2 seconds’ is not defined.
One object is actually a vector of periods of time and so can have a length of one for a single period of time or a length of ‘n’ for ‘n’ periods of time.
Slots
duration
:integer corresponding to the length of the period.
unit
:factor indicating the time unit of the period. See
POSIXt.units
to know available units.
Accessing to POSIXctp properties
A POSIXctp has several properties. Because a POSIXctp is a vector of
periodes of time, the class has a length
function. Other
properties are time properties : unit
and duration
allow to access to the corresponding properties.
The duration
of a period of time is an integer corresponding of the
time that the period last, in its time unit. The unit of a period of time
is an ordered factor as the one defined by POSIXt.units
.
A POSIXctp
can be converted to another time unit base (for instance
2 hours make 120 minutes). For that purpose the function unit<-
is
defined. The conversion will be effective only if the new unit can be exactly
defined as a multiple of the old one
(‘hour’ to ‘second’, ok ; ‘year’ to ‘month’, ok
; ‘month’ to ‘minute’ , NOT ok ; etc.
When conversion can not be done, the result has its unit unchanged.
Manipulating POSIXctp
Manipulating POSIXctp
means acting on POSIXctp
s like on classical
vectors. Methods available for this task allow to extract or replace parts of
a POSIXctp
(with the usual '[' operator), and to
concatenate (c
) or split POSIXctp
(split
). A unique
and a rep
method are defined to uniquify or repeat elements of a POSIXctp
.
match
and %in%
methods have also been
defined to find POSIXctp
objects among others.
Text representation
To represent a POSIXctp
available functions are print
,
summary
, head
,
tail
, show
and format
.
The five first functions work the same way that their generic definition.
POSIXctp
are formatted by pasting their duration (integer
)
with their unit (and with an ‘s’ if relevant).
Testing two POSIXctp
To test two POSIXctp the differents operators of comparison are used.
If the POSIXctp
compared
have a different length, the shorter is recycled over the longer so the
resulting vector (a logical vector) has length equal to the longer object.
Comparisons are made element by element. For a single comparison, first elements are converted into the same unit. If this is not possible, FALSE is returned if the test is ‘==’, TRUE if the test is ‘!=’, NA otherwise (elements can not be compared) ; else durations of elements are compared and the result of this comparison is returned.
Mathematical operations on POSIXctp
POSIXctp
can be added (or substracted) to differents type of objects :
to other POSIXctp
, to POSIXct
, to POSIXcti
and to
POSIXst
. POSIXctp
can also be multiplied by numeric
.
For all operations, if the two arguments have a different length, the shorter is recycled over the longer so the resulting vector (a logical vector) has length equal to the longer object.
Basic mathematical operation for POSIXctp
are (negative periods of
time can be defined !!) :
integer * POSIXctp
POSIXctp * integer
POSIXctp + POSIXctp
POSIXctp - POSIxctp
When POSIXctp
s do not have the same unit, an attempt is made to convert
one to the unit of the other, if it successes the operation is done otherwise
NA is returned.
Mathematical operations with POSIXct
, POSIXcti
and POSIXst
are actually time lagging. A POSIXct
to which a POSIXctp
is
added is lagged by the time periods indicated ; for a POSIXcti
, start
and end are lagged by the time periods.
For POSIXst
, units of the POSIXst
must be identical : the object
is then lagged by the time periods (if the result is higher than the maximum
the result is recycled at the begining. For instance :
saturday + 2 days = monday
).
POSIXct + POSIXctp
POSIXctp + POISXct
POSIXct - POSIXctp
.
POSIXcti + POSIXctp
POSIXctp + POISXcti
POSIXcti - POSIXctp
.
POSIXst + POSIXctp
POSIXctp + POISXst
POSIXst - POSIXctp
Changing class
POSIXctp
can be converted to numeric
with the as.numeric
method. The duration of the object is returned.
See Also
Examples
showClass("POSIXctp")