Learn R Programming

cycleRtools (version 1.0.0)

diff_section: Section data according to breaks.

Description

Generates a vector of "section" values/levels according to differences in the supplied vector. The function simply rolls over x, incrementing the return vector every time there is a significant break in the pattern of differences between adjacent elements of x. In practical terms, if x is a series of timestamp values (see example), every time there is a significant break in the timer (> 10 sec currently), the return vector is incremented by 1.

Usage

diff_section(x)

Arguments

x
a numeric vector (e.g. a timer column) that increments uniformly. When there is a significant break in this uniformity, a new section is created, and so forth.

Value

  • a vector of the same shape as x.

Examples

Run this code
t_sec <- c(1:10, 40:60, 100:150)       # Discontinuous timer values.
pwr   <- runif(length(t_sec), 0, 400)  # Some power values.
x     <- data.frame(t_sec, pwr)
# Generate section levels.
x$section <- diff_section(x$t_sec)
print(x)

Run the code above in your browser using DataLab