Q:

Can i apply sliding windows in a list of multible dataframes in r?

I have a list of around 400 dataframes and i want to extract features for each dataframe. The features are going to be the same for all the dataframes.
The dataframes consists of signals from an accelerometer and i will apply classification to identify different activities. Since my classes are based on specific patterns, i need my features (statistical, and frequency domain features) to be based on windowing. 
Can i do it straight to the list of dataframes? Extract features and then add the new feature columns back to the list for each dataframe?
Any advice will be appreciated. I am stuck. I know how to do it on each dataframe but is very time consuming with that amount of dataframes.
list example
# Dataframes, x and y are accelerometer measurements and a is annotation 
df1 <- data.frame(x = runif(10), y = runif(10), a = sample(c(1,2), 10, replace = TRUE)
df2 <- data.frame(x = runif(10), y = runif(10), a = sample(c(1,2), 10, replace = TRUE)
lst <- list(df1, df2)

The plan is to end up with many features for each dataframe and then merge all the dataframes together for feature selection and then classification.

A:

A combination of zoo::rollapply() and lapply() should do the trick.
set.seed(1)
df1 <- data.frame(x = runif(10), 
                  y = runif(10), 
                  a = sample(c(1,2), 10, replace = TRUE))
df2 <- data.frame(x = runif(10), 
                  y = runif(10), 
                  a = sample(c(1,2), 10, replace = TRUE))
lst <- list(df1, df2)

library(zoo)

lst_w <- lapply(lst, function(x) {
    cbind(x, a_w=rollapply(x$a, 3, mean, partial=TRUE))
    })

This will add a (mean) windowed version of column a to each data frame.
lapply(lst_w, head, 3)
# [[1]]
          # x         y a      a_w
# 1 0.2655087 0.2059746 2 1.500000
# 2 0.3721239 0.1765568 1 1.666667
# 3 0.5728534 0.6870228 2 1.333333

# [[2]]
          # x         y a      a_w
# 1 0.4820801 0.8209463 1 1.500000
# 2 0.5995658 0.6470602 2 1.333333
# 3 0.4935413 0.7829328 1 1.333333

You can replace mean in the rollapply() call with whatever function you want.

