Time series to Duration series
Arguments
- y
A time series, numeric vector, or categorical variable.
- timeVec
A vector, same length as
ycontaining timestamps, or, sample indices.- fs
Optional sampling frequency if timeVec represents sample indices. An extra column
duration.fswill be added which represents1/fs * duration in samples- tolerance
A number
tolindicating a range[y-tol,y+tol]to consider the same value. Useful whenyis continuous (default = 0)
See also
Other Time series operations:
ts_center(),
ts_changeindex(),
ts_checkfix(),
ts_detrend(),
ts_diff(),
ts_discrete(),
ts_embed(),
ts_integrate(),
ts_levels(),
ts_peaks(),
ts_permtest_block(),
ts_permtest_transmat(),
ts_rasterize(),
ts_sd(),
ts_slice(),
ts_slopes(),
ts_standardise(),
ts_sumorder(),
ts_symbolic(),
ts_trimfill(),
ts_windower()
Examples
library(invctr)
# Create data with events and their timecodes
coder <- data.frame(beh=c("stare","stare","coffee","type","type","stare"),t=c(0,5,10,15,20,25))
ts_duration(y = coder$beh, timeVec = coder$t)
#> y y.name t.start t.end duration.time duration.samples duration.fs
#> 1 1 stare 0 10 10 2 2
#> 2 2 coffee 10 15 5 1 1
#> 3 3 type 15 25 10 2 2
#> 4 1 stare 25 25 0 1 1
