I have accelerometer data with each row labelled for the behaviour an animal is displaying per second, simple example:
Time | X_accel | Behaviour |
---|---|---|
1 | 0.01 | Standing |
2 | 0.01 | Standing |
3 | 0.01 | Standing |
4 | 0.02 | Standing |
5 | 0.06 | Walking |
6 | 0.07 | Walking |
7 | 0.01 | Standing |
8 | 0.02 | Standing |
I've got a rolling window of functions being applied per behaviour - but I want them to be applied to each separate behaviour event rather than all of the data associated with for example "standing" grouped together.
Is it possible to make it recognise the end of each event and then start again at the beginning of the next one?
Alternatively I have considered whether it might be possible to add a 1 to "standing" for the first event (standing1) 2 to the second and so on throughout the data to make each event separate, although I'm not sure how I'd modify the code for it to recognise that and cycle through however many individual "standing" events there are.
lst1 <- lapply(df[df$Behaviour == behaviour, c(2)],
\(x) rollapply(x, FUN = time_domain_summary,
width = window.size, by = window.step,
align = c("left"), partial = FALSE))
where: "behaviour" is defined as standing, time_domain_summary = the features to calculate (mean, median etc.), window.size & window.step are defined e.g. size of 2 and step of 0.1
Currently the output is a rolling window across ALL rows containing "standing" in the behaviour column as if they were all one long event BUT I'd like them to be applied per individual event if possible.