Skip to contents

For each index <iStart> of vector values, this function tries to find a corresponding index <iStop> in such a way that the sum of the vector elements at indices between <iStart> and <iStop> reaches the given threshold. For each possible start index i, the algorithm starts either looking forward at indices i+1, i+2, ... or backwards at indices i-1, i-2, ..., accumulating the values at these indices. Once the accumulated sum reached the given threshold or if the difference between the indices exceeds the maximum allowed index difference maxDist the algorithm stops and continues with the next start index.

Usage

hsIntSumGeThreshold(
  tSeries,
  threshold,
  forward,
  maxTDiff,
  tsField = names(tSeries)[1],
  valField = names(tSeries)[2],
  valFactor = 1,
  includeIndices = TRUE,
  dbg = FALSE
)

Arguments

tSeries

data.frame with timestamps in first column and values in second column.

threshold

Threshold that shall be reached/exceeded by the sum of successive elements of values of which the maximum time difference is below or equal maxTDiff.

forward

If TRUE, the algorithm looks forward, else backwards, i.e. when looking forward (backwards), the start indices <iStart> are always less or equal (greater or equal) the assigned indices <iStop>.

maxTDiff

Maximum allowed time difference in seconds between two related timestamps.

tsField

Name of time stamp field; default: name of first column

valField

Name of value field containing the values of which the sum shall reach the threshold; default: name second column

valFactor

Factor to be applied to column valField before calculating value sums.

includeIndices

if TRUE, two columns iStart and iStop are included in the output data frame indicating the indices in tSeries corresponding to the timestamps tStart and tStop.

dbg

If TRUE, debug messages are shown

Value

data frame with columns iStart and iStop being the indices of tSeries that represent the beginning and the end of the time interval in which the value field sums up to at least threshold, tStart, tStop and tDiff representing the first timestamp, last timestamp and duration of the corresponding time intervals and the column sumWithin being the sum of values that was actially reached within the interval.