sample_values: Sample Values

Description Usage Arguments Value Methods (by class) Examples

View source: R/sampling.R

Description

Sample observation values from a time series at given sampling times.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
sample_values(x, ...)

## S3 method for class 'uts'
sample_values(
  x,
  time_points,
  interpolation = "last",
  max_dt = Inf,
  tolerance = .Machine$double.eps^0.5,
  ...
)

Arguments

x

a time series object.

...

further arguments passed to or from methods.

time_points

a strictly increasing sequence of POSIXct date-times.

interpolation

the interpolation method:

  • "last": for each sampling time, return the most recent (i.e. last available) observation value in x.

  • "linear": for each sampling time, return the linearily-interpolated value in x of the observation that immediately precedes and follows such sampling time.

max_dt

a duration object, specifying the maximum time difference between each sampling time and the observation times in x used for determining the sampled value. Return NA as sampled value for sampling times for which this threshold is exceeded.

tolerance

tolerance for numerical noise in observation times. See num_leq_sorted.

Value

An vector of sampled values with same length as the input x.

Methods (by class)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Sample the most recent observation
times <- as.POSIXct(c("2007-11-09", "2007-11-10"))
sample_values(ex_uts(), times)

# Sample with linear interpolation
sample_values(ex_uts(), times, interpolation="linear")

# Sample a non-numeric time series
sample_values(ex_uts2(), times)

# Error, because only numeric time series can be linearly interpolated
## Not run: sample_values(ex_uts2(), as.POSIXct("2007-01-01"), interpolation="linear")

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