title: Difference between acf and cor correlations
body: <p>I try to replicate the results from acf() with manually using cor(), and I get differences which I cannot understand.
  Consider the following toy example:</p>
  <pre><code># two slightly different lines, with a bit of noise
  # both are casted into time series
  foo &lt;- ts(seq(1:20) + rnorm(20))
  bar &lt;- ts((1.5*seq(1:20)-1) + rnorm(20))
  foobar=cbind(foo, bar)
  
  # lagged (auto)correlations, up to a lag of 10
  pippo &lt;- acf(foobar, 10)
  
  # look at the results; I see the two 'slices' of the resulting
  #   datacube: [ , , 1] and [ , , 2]. So far, so good.
  pippo$acf
  
  # 1st slice: [1,1,1] = 1 (obviously), and
  #   [2,1,1] = 0.82796109 (autocorrelation of foo with itself, lagged 1)
  
  # but if I do:
  cor(foobar[1:19, 1], foobar[2:20, 1])
  &gt; [1] 0.9669717
  </code></pre>
  <p>obviously, 0.82796109 is quite different from 0.9669717,
  and I cannot understand why. The same happens with cross-correlation
  between the two time series, one lagged with respect to the other.
  Even taking into account the
  (n-1/n) unbiased/biased factor that sometimes creeps in.
  What am I missing here?</p>
  <p>Many thanks in advance to whomever wants to help. And my apologies
  in advance if my question should come from a lack of understanding.
  Luca</p>
  <p>Environment: R 4.1.12, running on Win7</p>