title: several questions regarding zoo::rollapply
body: <p>My understanding of <code>rollapply</code>'s <code>width</code> option is that it specifies the window size on which the function will operate and <code>by</code> options specifies the shift size for this window. Here is my dataset:</p>
  
  <pre><code>&gt; dataset &lt;- as.vector(t(cbind(5:1, 1:5)))
  &gt; dataset
   [1] 5 1 4 2 3 3 2 4 1 5
  </code></pre>
  
  <p>And here are examples that confirms that I've written above:</p>
  
  <pre><code>&gt; w3b3 &lt;- rollapply(dataset, width = 3, by=3, FUN = print, align="left")
  [1] 5 1 4
  [1] 2 3 3
  [1] 2 4 1
  
  &gt; w3b2 &lt;- rollapply(dataset, width = 3, by=2, FUN = print, align="left")
  [1] 5 1 4
  [1] 4 2 3
  [1] 3 3 2
  [1] 2 4 1
  
  &gt; w2b3 &lt;- rollapply(dataset, width = 2, by=3, FUN = print, align="left")
  [1] 5 1
  [1] 2 3
  [1] 2 4
  
  &gt; w3b1 &lt;- rollapply(dataset, width = 3, by=1, FUN = print, align="left")
  [1] 5 1 4
  [1] 1 4 2
  [1] 4 2 3
  [1] 2 3 3
  [1] 3 3 2
  [1] 3 2 4
  [1] 2 4 1
  [1] 4 1 5
  
  # ACCORDING OT MAN WHEN NO VALUE IS USED THEN by=1 (SAME AS ABOVE)
  &gt; w3b1 &lt;- rollapply(dataset, width = 3, FUN = print, align="left")
  [1] 5 1 4
  [1] 1 4 2
  [1] 4 2 3
  [1] 2 3 3
  [1] 3 3 2
  [1] 3 2 4
  [1] 2 4 1
  [1] 4 1 5
  
  &gt; w1b1 &lt;- rollapply(dataset, width = 1, by=1, FUN = print, align="left")
  [1] 5
  [1] 1
  [1] 4
  [1] 2
  [1] 3
  [1] 3
  [1] 2
  [1] 4
  [1] 1
  [1] 5
  </code></pre>
  
  <p>Despite that I have several questions:</p>
  
  <p>1) Why this one returns error while <code>max(20)</code> is working? Everything is the same as in last example except <code>print</code> is replaced by <code>max</code>:</p>
  
  <pre><code>&gt; w1b1 &lt;- rollapply(dataset, width = 1, by=1, FUN = max, align="left")
  Error in if (is.na(a) || is.na(rval[i = 1]) || a == rval[i - 1]) max(xc[(i -  : 
    missing value where TRUE/FALSE needed
  </code></pre>
  
  <p>How can I debug those types <code>*apply</code> family function errors? </p>
  
  <p>2) What is the purpose of using vector larger than 1 in <code>with</code> option and why following code prints one number to output in odd positions but assigns two numbers in odd positions to <code>w12</code> variable? </p>
  
  <pre><code>&gt; w12 &lt;- rollapply(dataset, width = c(1,2), FUN = print, align="left")
  [1] 5
  [1] 1 4
  [1] 4
  [1] 2 3
  [1] 3
  [1] 3 2
  [1] 2
  [1] 4 1
  [1] 1
  &gt; w12
        [,1] [,2]
   [1,]    5    5
   [2,]    1    4
   [3,]    4    4
   [4,]    2    3
   [5,]    3    3
   [6,]    3    2
   [7,]    2    2
   [8,]    4    1
   [9,]    1    1
  
  # SAME AS ABOVE (ACCORDING TO MAN by IS USED ONLY IF width IS OF LENGTH 1)
  &gt; w12 &lt;- rollapply(dataset, width = c(1,2), by=10, FUN = print, align="left")
  [1] 5
  [1] 1 4
  [1] 4
  [1] 2 3
  [1] 3
  [1] 3 2
  [1] 2
  [1] 4 1
  [1] 1
  &gt; w12
        [,1] [,2]
   [1,]    5    5
   [2,]    1    4
   [3,]    4    4
   [4,]    2    3
   [5,]    3    3
   [6,]    3    2
   [7,]    2    2
   [8,]    4    1
   [9,]    1    1 
  </code></pre>
  
  <p>3) What is the difference between passing vector and list to <code>width</code> argument (compared to previous output this is totally different)?</p>
  
  <pre><code>&gt; rollapply(dataset, width = list(1,2), FUN = print, align="left")
  [1] 1
  [1] 2
  [1] 2
  [1] 3
  [1] 3
  [1] 4
  [1] 4
  [1] 5
  [1] 5
  [1] 1 2 2 3 3 4 4 5 5
  </code></pre>
  
  <p>4) what does <code>by.column</code> do? I was expecting that it has something to do with matrices so I've tried following:</p>
  
  <pre><code>&gt; mtrx &lt;- matrix(c(1:30), nrow=10)
  &gt; mtrx
        [,1] [,2] [,3]
   [1,]    1   11   21
   [2,]    2   12   22
   [3,]    3   13   23
   [4,]    4   14   24
   [5,]    5   15   25
   [6,]    6   16   26
   [7,]    7   17   27
   [8,]    8   18   28
   [9,]    9   19   29
  [10,]   10   20   30
  
  # THIS IS OK
  &gt; rollapply(mtrx, width = 2, by = 2, FUN = max, align = "left", by.column=T)
       [,1] [,2] [,3]
  [1,]    2   12   22
  [2,]    4   14   24
  [3,]    6   16   26
  [4,]    8   18   28
  [5,]   10   20   30
  
  # BUT WHAT IS THIS?
  &gt; rollapply(mtrx, width = 2, by = 2, FUN = max, align = "left", by.column=F)
  [1] 22 24 26 28 30
  </code></pre>