Description Usage Arguments Examples
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).
1 2 3 4 5 |
x |
a |
i |
either a strictly increasing sequence of |
j |
index specifying the time series to extract or replace. The index can be a |
drop |
logical. If |
... |
further arguments passed to |
value |
a vector of observation values, a |
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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.