parttime_extract: Indexing operators for partial_time objects

parttime_extractR Documentation

Indexing operators for partial_time objects

Description

Indexing operators repurpose matrix indexing for indexing into parttime fields. When only i is provided, the parttime vector is sliced. Whenever j is provided, the individual fields are indexed out of an internal matrix.

Usage

## S3 method for class 'partial_time'
x[i, j, ...]

## S3 method for class 'partial_time'
x[[i, j, ..., value]]

## S3 replacement method for class 'partial_time'
x[i, j, ..., reflow = TRUE] <- value

## S3 replacement method for class 'partial_time'
x[[i, ...]] <- value

Arguments

x

an object from which to extract element(s) or in which to replace element(s).

i

indicies specifying elements to extract or replace. For further details, see Extract.

j

column indicies specifying element(s) to extract or replace. For further details, see Extract.

...

arguments unused

value

typically an array-like R object of a similar class as x.

reflow

a logical indicating whether modified data fields should be reflowed, cascading range overflow. Setting to FALSE permits invalid dates, but saves on compute. Generally, it should only be disabled when multiple calculations are performed back-to-back and the dates only need to be reflowed once at the end of the calculation.

Value

A numeric matrix subset of the partial_time internal matrix representation. See the Details section of parttime for further information.

A numeric vector of the provided parttime field

the new value of the assigned partial_time object after modification.

A partial_time vector after modification

Examples

x <- as.parttime(c("2019", "2019-02", "2019-02-02"))
# <partial_time<YMDhms+tz>[3]>
# [1] "2019"       "2019-02"    "2019-02-02"

x[, c(1, 3)]
#            year day
# 2019       2019  NA
# 2019-02    2019  NA
# 2019-02-02 2019   2

x[, "month"]
#       2019    2019-02 2019-02-02
#         NA          2          2

x[, "month", drop = FALSE]
#            month
# 2019          NA
# 2019-02        2
# 2019-02-02     2

x <- as.parttime(c("2019", "2019-02", "2019-02-02"))
# <partial_time<YMDhms+tz>[3]>
# [1] "2019"       "2019-02"    "2019-02-02"

x[c(1, 3)] <- as.parttime(c("2000", "1999"))
# <partial_time<YMDhms+tz>[3]>
# [1] "2000"    "2019-02" "1999"

x[,"month"] <- 3
# <partial_time<YMDhms+tz>[3]>
# [1] "2000-03" "2019-03" "1999-03"


parttime documentation built on May 29, 2024, 6:25 a.m.