complement_periods: Find the complement of time periods

View source: R/utils.R

complement_periodsR Documentation

Find the complement of time periods

Description

Find the complement of a set of time periods in a set of epochs. For illustration, let's use integers instead of time periods and epochs. Suppose we have two intervals/periods, {[1,3], [8,10]}; their complement in the set {[0, ..., 12]} is {[0,0], [4,7], [11,12]}.

Usage

complement_periods(periods, epochs, start_var, end_var)

Arguments

periods

A data frame with at least two columns, start_var and end_var which are the first and the last epoch in a set of time periods, e.g. sleep periods or (non)wear periods.

epochs

A data frame with at least one column, timestamp, which contains POSIXct objects.

start_var

The variable (unquoted) which indicates when the time periods start.

end_var

The variable (unquoted) which indicates when the time periods end.

Value

A data frame of time periods with three columns: period_id (a sequential identifier), start_var (first epoch in period) and end_var (last epoch in period).

Examples

library("lubridate")
library("dplyr")
periods <- tibble(
  start = ymd_hm("2017-01-01 00:01"),
  end = ymd_hm("2017-01-01 00:05")
)
epochs <- tibble(timestamp = ymd_hm("2017-01-01 00:00") +
  minutes(0:12))
complement_periods(periods, epochs, start, end)

dipetkov/actigraph.sleepr documentation built on March 25, 2022, 2:33 a.m.