Learn R Programming

elpatron (version 0.0.4)

uniform_sampling: Make rows uniform

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

uniform_sampling(.data, time_column = "time.s", deltat = NULL, empty_fill = 0L)

Arguments

.data
data.frame; the data to be made uniform on the basis of time_column.
time_column
identifier for the column in data that gives (cumulative) time values. Right-hand-sided formulas will be deparsed, otherwise this argument is passed to '[[' as-is.
deltat
numeric (scalar); the typical sampling frequency of the data. If NULL (default), a guess is made via deltat_guess.
empty_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.

Value

a consistently sampled tbl_df, with the appropriate deltat attribute.

Details

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

Examples

Run this code
gappy_data <- data.frame(
  timer.s = c(1:100, 201:300),
  x = rnorm(200, 500, 30),
  y = rnorm(200, 1000, 300)
)
unif <- uniform_sampling(gappy_data, ~timer.s, empty_fill = NA)
head(unif)

Run the code above in your browser using DataLab