POSIXctp-class: Class '"POSIXctp"'

Description Usage Arguments Objects from the Class Slots Accessing to POSIXctp properties Manipulating POSIXctp Text representation Testing two POSIXctp Mathematical operations on POSIXctp Changing class See Also Examples

Description

Class that defines 'periods of time' objects such as 'one month', 'two months', 'three hours', 'four minutes', etc.

Usage

 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
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 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.

unit

A vector of factors defined by POSIXt.units() or a vector of character corresponding to the previous factors. See details below.

from

Object to convert to a period of time (actually works only for NA).

x

POSIXctp object on which the method has to be applied.

i

index (logical or numeric) of the POSIXctp objects.

value

New POSIXctp object.

f

factor used to group the POSIXctp elements.

drop

Argument specific to the split method. See link[base]{split} documentation.

object

POSIXctp object on which the method has to be applied.

table

The values (POSIXctp) to be matched against. See match for further details.

nomatch

The value to be returned i nthe case when no match is found. See match for further details.

incomparables

A vector of values that cannot be matched. See match for further details.

e1

POSIXctp, numeric or POSIXct. See details.

e2

POSIXctp, numeric or POSIXct. See details.

...

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 POSIXctps 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 !!) :

When POSIXctps 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).

Changing class

POSIXctp can be converted to numeric with the as.numeric method. The duration of the object is returned.

See Also

POSIXct, POSIXcti, POSIXst

Examples

1
showClass("POSIXctp")

timetools documentation built on May 2, 2019, 7:24 a.m.