One of the columns in my dataset is "Movement_Stats", it contains "forward", "backward" and "Stop". Each row represents an image frame. So this column looks like: "forward, forward, forward, backward, forward, forward...". I want to smooth the categorical values of this column by the rule:
I did not find any package I can use in R.
You can use rollapply
from package zoo
together with table
:
mov <- c("forward", "backward", "stop")
s <- sample(mov, 1000, replace = TRUE)
zoo::rollapply(s,11, function(x) names(which.max(table(x))))