Works exactly like subsetting base vectors via [, but preserves the date_xx class and subclasses. The replacement functions [<- and [[<- conduct additional checks before assignment to prevent the generation of degenerate date_xx vectors (see examples).

# S3 method for date_xx
[(x, i)

# S3 method for date_yq
[(x, i) <- value

# S3 method for date_ym
[(x, i) <- value

# S3 method for date_yw
[(x, i) <- value

# S3 method for date_xx
[[(x, i)

# S3 method for date_yq
[[(x, i) <- value

# S3 method for date_ym
[[(x, i) <- value

# S3 method for date_yw
[[(x, i) <- value

Arguments

x

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

i

indices specifying elements to extract or replace. Indices are numeric or character vectors or empty (missing) or NULL. Numeric values are coerced to integer as by as.integer (and hence truncated towards zero). Character vectors will be matched to the names of the object (or for matrices/arrays, the dimnames): see ‘Character indices’ below for further details.

For [-indexing only: i, j, ... can be logical vectors, indicating elements/slices to select. Such vectors are recycled if necessary to match the corresponding extent. i, j, ... can also be negative integers, indicating elements/slices to leave out of the selection.

When indexing arrays by [ a single argument i can be a matrix with as many columns as there are dimensions of x; the result is then a vector with elements corresponding to the sets of indices in each row of i.

An index value of NULL is treated as if it were integer(0).

value

A vector of the same class as x or a vector of integers that correspond to the internal representation date_yq/date_ym/date_yw objects (see examples)

Value

a date_xx vector

See also

Examples

x <- date_yq(2016, 1:4) x[[2]]
#> [1] "2016-Q2"
x[1] <- date_yq(2016, 3) x[2] <- 20164 # 2016, 4th quarter x[1:2]
#> [1] "2016-Q3" "2016-Q4"
# Trying to assign illegal values for the respective date_xx type raises an error try(x[2] <- 20165)
#> Error : 'value' is not a valid date_yq (yyyyq)
x <- date_ym(2016, 1:3) x[1] <- 201610 # October 2016 x <- date_yw(2016, 50:52) x[1] <- 201649 # 2016, week 52