Let's say I have a data frame with columns of data, and I want to calculate the one-sided moving average of each column. Why does this work
my.rollapply <- function(x){
return(rollapply(x,moving.avg,FUN= mean, fill = NA,align = 'right', na.rm = TRUE))
}
averageData <- apply(averageData, 2, my.rollapply)
but
averageData <- apply(averageData, 2, rollapply, width = moving.avg, FUN = mean, fill = NA, align = 'right', na.rm = TRUE)
gives me an error of
Error in mean.default(newX[, i], ...) :
'trim' must be numeric of length one
Is this because mean itself requires additional parameters? How would I be able to pass in all the parameters to rollapply inside of apply then?