title: Calculate the mean of every 13 rows in data frame
body: <p>I have a data frame with 2 columns and 3659 row <code>df</code></p>
  
  <p>I am trying to reduce the data set by averaging every 10 or 13 rows in this data frame, so I tried the following :</p>
  
  <pre><code># number of rows per group
  n=13
  # number of groups
  n_grp=nrow(df)/n
  round(n_grp,0)
  # row indices (one vector per group)
  idx_grp &lt;- split(seq(df), rep(seq(n_grp), each = n))
  
  # calculate the col means for all groups
  res &lt;- lapply(idx_grp, function(i) {
    # subset of the data frame
    tmp &lt;- dat[i]
    # calculate row means
    colMeans(tmp, na.rm = TRUE)
  })
  # transform list into a data frame
  dat2 &lt;- as.data.frame(res)
  </code></pre>
  
  <p>However, I can't divide my number of rows by 10 or 13 because data length is not a multiple of split variable. So I am not sure what should do then (I just want may be to calculate the mean of the last group -even with less than 10 elements)</p>
  
  <p>I also tried this one, but the results are the same:</p>
  
  <pre><code>df1=split(df, sample(rep(1:301, 10)))
  </code></pre>