Time series to Duration series
A time series, numeric vector, or categorical variable.
A vector, same length as y
containing timestamps, or, sample indices.
Optional sampling frequency if timeVec represents sample indices. An extra column duration.fs
will be added which represents 1/fs * duration in samples
A number tol
indicating a range [y-tol,y+tol]
to consider the same value. Useful when y
is continuous (default = 0
)
A data frame
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()
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