Skip to contents

Calculate the duration of time VALUE exceeds a threshold (above or below)

Usage

calculate_event_duration(
  dat,
  threshold,
  ...,
  less_than = TRUE,
  summary_table = TRUE
)

Arguments

dat

Data frame with columns VALUE (numeric), TIMESTAMP (POSIXct), and a column for each grouping variable in ....

threshold

Threshold value that triggers start of event. Event starts when VALUE is greater than (less than) OR equal to threshold.

...

Grouping variables. Must be name(s) of column(s) in dat.

less_than

Logical argument. If TRUE, function identifies events when VALUE was less than or equal to threshold; if FALSE, the function identifies events when VALUE was greater than or equal to threshold.

summary_table

Logical argument. If FALSE, function will return table with all events for each grouping variable. If TRUE, function will return summary table with maximum event duration for each grouping variable.

Value

Returns a data frame.