resample: Resample data

Description Usage Arguments Details Value Examples

Description

A useful function for working with data that aren't sampled at regular intervals and(or) contain gaps. This can present issues when, for example, trying to apply time-windowed rolling operations.

Usage

1
resample(.data, time_column = "time.s", Hz = 1L, fill = 0L)

Arguments

.data

data.frame; the data to be resampled on the basis of time_column.

time_column

string; identifier for the column in data that gives (elapsed) time values. Right-hand-sided formulas will be deparsed, otherwise this argument is passed to '[[' as-is.

Hz

numeric (scalar); the desired sampling frequency.

fill

the value with which to "fill" new rows in the returned data. For most purposes this should be either NA or a numeric value (e.g. 0).

Details

For time-windowed rolling operations, fill should logically be set to 0L; the use of NAs could generate large runs of NAs.

Value

a resampled tbl_df, with a new Hz attribute added.

Examples

1
2
3
4
5
6
7
data <- data.frame(
  timer.s = 1:500,
  x = rnorm(500, 500, 30),
  y = rnorm(500, 1000, 300)
)
gappy_data <- data[sort(sample(1:500, 250)), ]
gappy_data %>% resample(~timer.s, Hz = 1, fill = NA) %>% head(20)

jmackie4/elpatron documentation built on May 19, 2019, 12:49 p.m.