merge_periods: Merge time intervals

View source: R/merge_periods.R

merge_periodsR Documentation

Merge time intervals

Description

Join adjacent or redundant time intervals across ids

Usage

merge_periods(
  df,
  start_time,
  end_time,
  ...,
  tolerance = 0,
  units = "minutes",
  simplify = TRUE,
  plots = FALSE
)

Arguments

df

A dataframe

start_time

The unquoted name of the starting time column in df

end_time

The unquoted name of the ending time column in df

...

Optional grouping columns, unquoted

tolerance

A number specifying how far apart start and end times can be to combine.

units

The units for tolerance. One of c('seconds', 'minutes', 'hours', 'days', 'years')

simplify

Should the results be simplified and joined?

plots

Should plots be generated for each group?

Author(s)

Sven Halvorson

Examples

data(periods_data)
merged_periods = merge_periods(
  periods_data,
  start_time = ts_start,
  end_time = ts_end,
  id,
  tolerance = 3,
  units = 'minutes',
  simplify = FALSE,
  plots = TRUE
)

SvenR::ggslideshow(merged_periods$plot)

svenhalvorson/SvenR documentation built on Aug. 25, 2023, 1:31 p.m.