To fix the issue you can do I am not sure if you can apply the rollapply to the entire dataframe. You can apply it to every column separately with lapply and since you want sum of second and third element you can reduce the width as 2 instead

code :

```
library(zoo)
lapply(dfxts, function(x) rollapply(x, width = 2, FUN=sum))
#$A
# A
#1970-01-31 NA
#1970-02-01 3
#1970-02-02 5
#1970-02-03 7
#1970-02-04 9
#1970-02-05 11
#1970-02-06 13
#1970-02-07 15
#1970-02-08 17
#$B
# B
#1970-01-31 NA
#1970-02-01 7
#1970-02-02 9
#1970-02-03 11
#1970-02-04 13
#1970-02-05 15
#1970-02-06 17
#1970-02-07 19
#1970-02-08 21
```

```
lapply(dfxts, function(x) rollapply(x, width = 3, FUN=function(y) sum(y[2],y[3])))
```

```
rollapply(dfxts, width = 3, FUN=function(x) coredata(x[2]) + coredata(x[3]))
```

```
rollapply(dfxts, width = 15, FUN=function(x) {
vals <- coredata(x)
5*vals[5] - 8*vals[7] + vals[15]
})
```