epoch_length_sec: Determine epoch length in seconds

View source: R/dates_and_times.R

epoch_length_secR Documentation

Determine epoch length in seconds

Description

Determine epoch length in seconds

Usage

epoch_length_sec(timestamps, digits = 6)

Arguments

timestamps

POSIX-formatted input

digits

for rounding. See details

Details

The function is designed to work even when the epoch length is less than one second (e.g., for raw accelerometry data). Thus, it is not possible to base the code on convenient difftime methods. Instead, numeric operations are performed after running unclass on the input. This sometimes results in miniscule fluctuations of the calculated epoch length (e.g., +/- 0.0000002). Thus, the code rounds everything to the precision indicated by digits. For most applications, the default value (digits = 6) should be well past the range of meaningful fluctuations and lead to a favorable outcome. But the ditits argument can also be adjusted if greater assurance is needed.

After rounding, the code checks for the existence of multiple epoch lengths. If they are detected (e.g., due to a discontinuity in the file), a warning is issued and the most prevalent epoch length is returned. The warning will specify all the different epoch lengths that were detected, which may be useful information for troubleshooting.

Value

The epoch length of the data, in seconds

Examples

epoch_length_sec(Sys.time() + 0:5)
epoch_length_sec(Sys.time() + seq(0, 25, 5))

PAutilities documentation built on Aug. 21, 2022, 9:05 a.m.