My imported data contains 7 variables: Y and X1, X2, X3, X4, X5, X6. I tried apply
It is not really clear what your data actually is (use dput(example_data) to give reproducible examples).
But the lm call in your example is simply doing the same regression over and over again (your x is not changing) and as josilber points out, it is supposed to be a function. Here is an example where all the data is in the data.frame allRegData and it has at least two columns, one named y and another named x:
require(zoo)
rollapply(zoo(allRegData),
width=262,
FUN = function(Z)
{
t = lm(formula=y~x, data = as.data.frame(Z), na.rm=T);
return(t$coef)
},
by.column=FALSE, align="right")