title: Moving Average using R code
body: <p>The first part I need to have R code is about: </p>
  
  <blockquote>
    <p>Write an R function that does the following: Given a sequence xN = (x1; x2; ...; xN) of N
        observations, the function returns a vector of moving averages, where each average is computed
        with k consecutive observations. Name the function ma, and its arguments are the
        vector xN and k.</p>
  </blockquote>
  
  <p>What I have so far:</p>
  
  <pre><code>x &lt;-vector(length=n)
  
  ma &lt;- function(x,k){
  x0 &lt;- x[1:(length(x)-k)]
  x1 &lt;- x[(1+k):length(x)]
  cor(x0, x1)
  }
  </code></pre>
  
  <p>I'm pretty sure that I made mistakes... </p>