Learn R Programming

timetools (version 1.5.2)

unit: define valid units for time objects/retrieve-set time unit of a time object

Description

The timetools package use a set of valid time units which are roughly : year, month, week, day, hour, minute, second. They can be combined in subtime objects. For instance : month of year, minute of day, minute of week, etc.

Usage

POSIXt.units(x = NULL, ...)

unit(x, ...) unit(object) <- value of(x, ...)

## S3 method for class 'POSIXst': unit(x, ...) ## S3 method for class 'POSIXst': of(x, ...)

## S3 method for class 'POSIXctp': unit(x, ...) ## S3 method for class 'POSIXctp': unit(object) <- value

Arguments

x
a character string representing the needed units for POSIXt.units. The object from which the time unit is to retrieve.
object
POSIXctp to which the unit is to be changed
value
a character or a POSIXt.units indicating the new units of object.
...
arguments to or from other methods

POSIXt.units(x = NULL, ...)

With no argument, the function return a factor containing the valid time units. With an argument, it returns the units asked for.

unit(x, ...)

Return the time unit of the object. In case 'x' is a POSIXst, the unit is the 'left' part of its unit : if 'x' is a 'minute of day', 'unit' will return 'minute'.

of(x, ...)

For POSIXst only, it return the 'right' part of the unit of 'x' : if 'x' is a 'minute of day', 'of' will return 'day'.

unit('POSIXctp') &lt;- value

This function is used to convert period objects from its unit to a new one (for instance, from 'year's to 'month's : 1 year = 12 months).

The conversion will be effective only if it makes sense (hour to second, ok ; year to month, ok ; month to minute , NOT ok ; etc.