title: How to subtract the moving-average results from the corresponding original values?
body: <p>This line given below will simply calculate the moving average for certain values with a window of 3. As the total number of values is 12 and the moving-average widow is 3, the number of resulted values is 10 (as shown below).</p>
  
  <pre><code>library(zoo)
  x &lt;- c(1,2,3,NA,NA,4,6,5,6,4,2,5)
  movingmean &lt;- rollapply(x, 3, FUN = mean, na.rm = T)
  movingmean
  #  [1] 2.000000 2.500000 3.000000 4.000000 5.000000 5.000000
  #  [7] 5.666667 5.000000 4.000000 3.666667
  </code></pre>
  
  <p>I want to subtract these averages (<code>movingmean</code>) from the corresponding original value.   </p>
  
  <p><strong>Example:</strong> <code>2-2.000000, 3-2.500000, NA-3.000000, NA-4.000000, ..., 2-3.666667</code>.</p>