tspan: Determine Time Span of Time Indices and Time Intervals

View source: R/tspan.R

tspanR Documentation

Determine Time Span of Time Indices and Time Intervals

Description

tspan method determines the time span of time indices and time intervals.

Usage

tspan(x, ...)

## Default S3 method:
tspan(x, ...)

## S3 method for class 'tind'
tspan(x, na.rm = FALSE, ...)

## S3 method for class 'tinterval'
tspan(x, ...)

Arguments

x

an object of tind class (or of other time index class supported by tind package) or an object of tinterval class.

...

further arguments passed to or from other methods.

na.rm

a logical value indicating whether missing values should be removed.

Details

Given tind argument, tspan returns a single tdiff (or a single number for types "i" and "n") giving time span of indices.

tspan for tinterval argument returns a tdiff of the same length as the argument giving spans of time intervals.

Time spans are determined differently for time indices representing periods of time (for example days) and for time indices that represent points in time as determined by is.instant function. A sequence of 3 consecutive dates has span of 3 days and a sequence of 5 consecutive integers has span 5. On the other hand, a sequence of 3 consecutive hours will have span of 2 hours, the difference between the last and the first hour, see Examples.

Value

A tdiff or a numeric vector (for integer and numeric indices).

See Also

tinterval class, is.instant function, resolution_t method for determining the resolution of time indices, is.regular method for checking if time indices form a regular sequence.

Examples

# 4 consecutive days
(x <- today() + 0:3)
tspan(x)
# 10 consecutive integers
(x <- as.tind(1:10, "i"))
tspan(x)
# 4 consecutive hours
(x <- tind(H = 12:15))
# span is 3 hours (not 4)
tspan(x)
# the same
tind(H = 15) - tind(H = 12)


tind documentation built on Dec. 28, 2025, 1:06 a.m.