sample_values.uts_vector: Sample Values

Description Usage Arguments Value Examples

View source: R/sampling.R

Description

Sample each time series in a "uts_vector" at given sampling times and combine the sampled values into a matrix or data.frame.

Usage

1
2
## S3 method for class 'uts_vector'
sample_values(x, time_points, ..., drop = TRUE)

Arguments

x

a "uts_vector" object where each individual "uts" as atomic observation values.

time_points

a strictly increasing sequence of POSIXct date-times.

...

arguments passed to sample_values.uts for sampling from the individual time series.

drop

logical. If TRUE the result is coerced to the lowest possible dimension. See the examples and drop.

Value

A matrix if all sampled observation values are of the same type, and a data.frame otherwise. However, when using argument drop=TRUE the result may be simplified further.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
times <- as.POSIXct(c("2007-11-09", "2007-11-10"))

# Sample with last-point and linear interpolation
sample_values(ex_uts_vector(), times)
sample_values(ex_uts_vector(), times, interpolation="linear")

# Sample with and without dropping of length-one dimensions
sample_values(ex_uts_vector(), times[1])
sample_values(ex_uts_vector(), times[1], drop=FALSE)

# Store sampled values in data.frame if of different type
x <- ex_uts()
y <- uts(letters[1:6], x$times)
utsv <- c(x, y)
sample_values(utsv, times)

# Error, because not all time series have atomic observation values
## Not run: sample_values(ex_uts_vector2(), times)

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