"POSIXctp"
Class that defines 'periods of time' objects such as 'one month', 'two months', 'three hours', 'four minutes', etc.
POSIXctp(duration, unit)
as.POSIXctp(from, ...) # S3 method for POSIXctp
[(x, i, ...)
# S3 method for POSIXctp
[(x, i) <- value
# S3 method for POSIXctp
c(...)
# S3 method for POSIXctp
split(x, f, drop=FALSE, ...)
# S3 method for POSIXctp
rep(x, ...)
# S3 method for POSIXctp
unique(x, incomparables=FALSE, ...)
# S4 method for POSIXctp
unit(x, ...)
# S4 method for POSIXctp
unit(object) <- value
# S4 method for POSIXctp
duration(x, ...)
# S4 method for POSIXctp
length(x)
# S3 method for POSIXctp
print(x, ...)
# S3 method for POSIXctp
format(x, ...)
# S3 method for POSIXctp
summary(object, ...)
# S3 method for POSIXctp
head(x, ...)
# S3 method for POSIXctp
tail(x, ...)
# S4 method for POSIXctp
show(object)
# S4 method for POSIXctp,POSIXctp
match(x, table, nomatch = NA_integer_, incomparables=NULL)
# S4 method for POSIXctp,ANY
match(x, table, nomatch = NA_integer_, incomparables=NULL)
# S4 method for POSIXctp,ANY
%in%(x, table)
# S3 method for POSIXctp
Ops(e1, e2)
# S4 method for numeric,POSIXctp
*(e1, e2)
# S4 method for POSIXctp,numeric
*(e1, e2)
# S4 method for POSIXctp,POSIXctp
+(e1, e2)
# S4 method for POSIXctp,POSIXctp
-(e1, e2)
# S4 method for POSIXct,POSIXctp
+(e1, e2)
# S4 method for POSIXctp,POSIXct
+(e1, e2)
# S4 method for POSIXct,POSIXctp
-(e1, e2)
# S4 method for POSIXctp
as.numeric(x, ...)
A vector integer
indicating the duration of period (2 for
2 monthes, 1 for 1 year, etc). If a vector of numeric
is given, it
will coerced to an integer
. Can be missing, see details below.
A vector of factors defined by POSIXt.units
() or
a vector of character
corresponding to the previous factors.
See details below.
Object to convert to a period of time (actually works only for
NA
).
POSIXctp
object on which the method has to be applied.
index (logical
or numeric
) of the POSIXctp objects.
New POSIXctp
object.
factor
used to group the POSIXctp
elements.
Argument specific to the split method. See link[base]{split}
documentation.
POSIXctp
object on which the method has to be applied.
The values (POSIXctp
) to be matched against. See
match
for further details.
The value to be returned i nthe case when no match is found.
See match
for further details.
A vector of values that cannot be matched.
See match
for further details.
POSIXctp
, numeric
or POSIXct
. See details.
POSIXctp
, numeric
or POSIXct
. See details.
More arguments.
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.
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.
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
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.
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).
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.
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
POSIXctp
can be converted to numeric
with the as.numeric
method. The duration of the object is returned.
POSIXct
, POSIXcti
,
POSIXst