sub-.uts: Extract or Replace Parts of a uts

Description Usage Arguments Examples

Description

The accessor method ("[") extracts a sub-sampled time series with the provided times. The replacement method ("[<-") inserts observation values at the provided observation times, replacing observations values for already existing observation times (if any).

Usage

1
2
3
4
5
## S3 method for class 'uts'
x[time_points, ...]

## S3 replacement method for class 'uts'
x[time_points, ...] <- value

Arguments

x

a "uts" object.

time_points

either a strictly increasing sequence of POSIXct date-times, or a "uts" with logical observation values.

...

further arguments passed to sample_values.

value

a vector of observation values to insert at the time points time_points.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# Sample at single time point
ex_uts()[as.POSIXct("2000-01-01")]

# Sample at multiple time points, optionally restricting the maximum time difference
# between sampling and observation times
times <- as.POSIXct(c("2007-11-08 11:01:00", "2007-11-09 15:16:00"))
ex_uts()[times]
ex_uts()[times, max_dt = dhours(1)]
# Insert multiple numeric values
test <- ex_uts()
test[Sys.time() + ddays(1:2)] <- c(51, 52)

# Insert non-numeric value
test <- ex_uts()
test[Sys.time() + ddays(3)] <- list(cat=1, dog=2)

# Replacement times from logical "uts"
test <- ex_uts()
test[test >= 48] <- 50

andreas50/uts documentation built on April 8, 2021, 10:03 a.m.