2
$\begingroup$

I have read the description of by.column for rollapply in the manual but i couldn't understand how to use it. see below:

x=matrix(1:60,nrow=10)

rollapply(x,3,mean,fill=NA,align="right",by.column=FALSE)

 [1] NA NA 27 28 29 30 31 32 33 34

when i use by.column= FALSE: it applies mean to width (3) rolling number of lines mean(x[1:3,])

now, if i use by.column=TRUE then i get:

x=matrix(1:60,nrow=10)

rollapply(x,3,mean,fill=NA,align="right",by.column=TRUE)

     [,1] [,2] [,3] [,4] [,5] [,6]

[1,]  NA   NA   NA   NA   NA   NA

[2,]  NA   NA   NA   NA   NA   NA

[3,]  2   12   22   32   42   52

[4,]  3   13   23   33   43   53

[5,]  4   14   24   34   44   54

[6,]  5   15   25   35   45   55

[7,]  6   16   26   36   46   56

[8,]  7   17   27   37   47   57

[9,]  8   18   28   38   48   58

[10,] 9   19   29   39   49   59

i can't make sense of the result. could anyone please explain what's the use of by.column and maybe provide an example? Thanks

$\endgroup$
2
  • $\begingroup$ I'm voting to close this question as off-topic because it does not appear to be about quantitative finance within the scope defined in the help center. $\endgroup$
    – olaker
    Commented Oct 5, 2015 at 13:47
  • $\begingroup$ @olaker: this was cross-posed on stats.SE (migrated to SO) $\endgroup$ Commented Oct 5, 2015 at 21:36

0

Browse other questions tagged or ask your own question.