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

Description Usage Arguments Examples

Description

The accessor method ("[") extracts either (i) a sub-sampled time series vector, (ii) a subset of the time series vector, or (iii) both. 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_vector'
x[i, j, drop = TRUE, ...]

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

Arguments

x

a "uts_vector" object.

i

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

j

index specifying the time series to extract or replace. The index can be a numeric or character vector 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.

drop

logical. If TRUE the result is coerced to the lowest possible dimension.

...

further arguments passed to sample_values.uts.

value

a vector of observation values, a "uts", a or "uts_vector".

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
##############################
# Subsampling and Subsetting #
##############################

# Extract subset of time series vector
x <- ex_uts_vector()
x[, 1]
x[, "oranges", drop=FALSE]
x[, 2:1]

# Subsampling using a POSIXct vector
x <- ex_uts_vector()
times <- as.POSIXct(c("2007-11-08 11:01:00", "2007-11-09 15:16:00"))
x[times]
x[times, interpolation="linear"]

# Subsampling using a "uts" with logical observation values
x <- ex_uts_vector()
x[ex_uts() > 48]

# Subsampling and subsetting at the same time
# 1.) using separate subsampling and subsetting indicies
x[times, "oranges"]
x[times, c(1, 2, 1)]
# 2.) using "uts_vector" with logical observation values
x[x > 48]


###############################
# Replacements and Insertions #
###############################

# Replace subset of time series vector with a single new "uts" time series
x <- ex_uts_vector()
x[, "oranges"] <- uts(values=50, times=Sys.time())
x[, "nuts"] <- head(ex_uts(), 2)
x[, "apples"] <- NULL

# Same, but use "uts_vector" for replacing
x <- c(ex_uts_vector(), nuts=ex_uts())
x[, 1:2] <- c(uts(), ex_uts())
x[, c("apples", "oranges")] <- NULL

# Replace/insert observations of single time series
# 1.) Insert single value into the first time series 
# 2.) Insert multiple values into the time series named "oranges"
x <- ex_uts_vector()
x[Sys.time(), 1] <- 50
x[Sys.time() + ddays(1:2), "oranges"] <- c(52, 53)

# Replace/insert observations of multiple time series
# 1.) Insert single value into every time series
# 2.) Insert the same multiple values into every time series
x <- ex_uts_vector()
x[Sys.time(), ] <- 51
x[Sys.time() + ddays(1:2), ] <- c(52, 53)

# Take replacement times from "uts" or "uts_vector" with logical observation values
x <- ex_uts_vector()
x[ex_uts() > 48] <- 5
x[x == 5] <- 6

andreas50/utsMultivariate documentation built on Sept. 27, 2021, 10:33 p.m.