Run-length-encodes per-frame state and point variables into the
long-format anievent(). Works on a data frame (with bare-name
selection of the event columns and explicit time / identity)
or on an aniframe() (where everything is read from metadata).
Usage
to_anievent(data, ...)
# S3 method for class 'anievent'
to_anievent(data, ...)
# S3 method for class 'data.frame'
to_anievent(
data,
time,
state = NULL,
point = NULL,
variables_what = NULL,
variables_when = NULL,
metadata = list(),
...
)
# S3 method for class 'aniframe'
to_anievent(
data,
variables_what = NULL,
variables_when = NULL,
metadata = list(),
...
)Arguments
- data
A data frame or an
aniframe().- ...
Passed to methods.
- time
For data-frame input, the column holding per-frame times. Bare name (tidyselect). Required.
- state
For data-frame input, columns to run-length-encode as state bouts. Bare names (tidyselect). Logical columns produce bouts on TRUE-runs, labelled by the column name; factor or character columns produce one bout per contiguous non-
NArun of the same value.- point
For data-frame input, columns to encode as point bouts. Bare names (tidyselect). Logical columns produce one point bout per TRUE frame, labelled by the column name; factor or character columns produce one bout per non-
NAframe.- variables_what
For data-frame input, identity columns (e.g.
individual). Bare names (tidyselect). Bouts are isolated per identity group.- variables_when
For data-frame input, additional temporal- grouping columns (e.g.
observation,session,trial). Bare names (tidyselect). Like identity, these isolate bouts.- metadata
Optional list of metadata attached to the result. For an aniframe input, fields like
unit_timeandsampling_rateare propagated automatically;metadataoverrides those.
Value
An anievent().
Details
Distinct from as_anievent(): that one is a strict cast — the
input must already be in canonical anievent shape (one row per
bout, with channel / type / label / start / stop).
to_anievent() is the encoding verb that produces that shape
from per-frame data.
Examples
if (FALSE) { # \dontrun{
library(tibble)
df <- tibble(
individual = 1L,
time = 1:8,
behaviour = factor(c("REM", "REM", "REM", "wake", "wake", "REM", "REM", NA)),
woke_up = c(FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE),
call = c(NA, "alarm", NA, NA, NA, NA, NA, NA)
)
to_anievent(
df,
time = time,
state = c(behaviour, woke_up),
point = call,
variables_what = individual
)
} # }