Skip to contents

Increase or decrease the number of observations in a data frame using linear interpolation for up- and down-sampling.

Usage

resample_data(
  data,
  time_channel = NULL,
  sample_rate = NULL,
  resample_rate = NULL,
  resample_time = NULL,
  na.rm = FALSE,
  verbose = TRUE
)

Arguments

data

A data frame.

time_channel

A character string indicating the time or sample data column. Must match data column names exactly. Will be taken from metadata if not defined explicitly.

sample_rate

A numeric value for the sample rate in Hz. Will be taken from metadata or estimated from time_channel if not defined explicitly.

resample_rate

An optional numeric value indicating the desired output sample rate (in Hz) to convert the data frame. Setting resample_rate = sample_rate will interpolate over missing and repeated samples within the bounds of the existing data. If both resample_rate = NULL and resample_time = NULL (the default), the original data frame will be passed through.

resample_time

An optional numeric value indicating the desired sample time (in seconds) to convert the data frame.

na.rm

A logical indicating whether NAs should be interpolated across or passed through to the re-sampled data frame.

na.rm = TRUE

Will use stats::approx() method = "linear" to interpolate across NAs and any new samples. Leading and trailing NAs will be filled by applying rule = 2.

na.rm = FALSE

(The default) will pass through NAs from the original data, and any new samples will be NA.

verbose

A logical. TRUE (the default) will return warnings and messages which can be used for data error checking. FALSE will silence these messages. Errors will always be returned.

Value

A tibble of class mnirs.data with metadata available with attributes().

Details

time_channel and sample_rate will be taken from metadata for a data frame of class "mnirs.data which has been processed with {mnirs}, if not specified explicitly.

Otherwise, sample_rate will be estimated from the values in time_channel. However, this may return unexpected values, and it is safer to define sample_rate explicitly.

The default setting resample_rate = sample_rate will interpolate over missing and repeated samples within the bounds of the existing data. Setting both resample_rate = NULL and resample_time = NULL (the default) will pass through the original data frame.