mapToDiscreteTime: Map Irregular Data to a Discrete Time Grid via Interpolation

Description Usage Arguments Details Value Examples

Description

This function takes irregularly-spaced observations in time and, through a call to approx, interpolates the data at a user-specified, fixed grid of equally-spaced time points. The function is essentially a wrapper to approx that allows data frames as input (as opposed to individual vectors for the x variable and time variable). As such, it provides a useful framework for grouped data operations such as plyr::ddply.

Usage

1
2
mapToDiscreteTime(data, xvar = "value", timevar = "t", start, end, dt,
  method = "constant", rule = 2, ...)

Arguments

data

A data frame

xvar

Character string indicating the column name in data that contains the measurements

timevar

Character string indicating the column name in data that contains the (numeric) time values associated with the measurements in xvar.

start

Numeric value of the starting time over which the discrete time data will be generated. Defaults to min(data$xvar).

end

Numeric value of the ending time over which the discrete time data will be generated. Defaults to max(data$xvar).

dt

Numeric value representing the time increment of measurements over the time interval given by start and end. Must satisfy dt <= (end - start).

method

Interpolation method passed to approx(). Defaults to "constant". See help(approx) for details.

rule

Rule by which observations outside the interval [min(data$xvar), max(data$xvar)] are handled. Defaults to rule=2; see help(approx) for details.

...

Other parameters passed to approx().

Details

The function ignores columns in data other than xvar and timevar.

Value

A data frame containing equally-spaced, interpolated values of xvar over the specified time grid. Other variables in data are returned (assuming)

Examples

1
2
3
irregularData <- tibble(value=1:10, t=c(1,4,5,7,8,10,11,13,17,21))
mapToDiscreteTime(irregularData, end=24, dt=2)
mapToDiscreteTime(irregularData, end=24, dt=0.5)

jarrod-dalton/discretetime documentation built on May 16, 2019, 7:13 p.m.