Calculating length of 95%-CI using dplyr : <p>Last time I asked how it was possible to calculate the average score per measurement occasion (week) for a variable (procras) that has been measured repeatedly for multiple respondents. So my (simplified) dataset in long format looks for example like the following (here two students, and 5 time points, no grouping variable):</p>

<pre><code>studentID  week   procras
   1        0     1.4
   1        6     1.2
   1        16    1.6
   1        28    NA
   1        40    3.8
   2        0     1.4
   2        6     1.8
   2        16    2.0
   2        28    2.5
   2        40    2.8
</code></pre>

<p>Using dplyr I would get the average score per measurement occasion</p>

<pre><code>mean_data &lt;- group_by(DataRlong, week)%&gt;% summarise(procras = mean(procras, na.rm = TRUE))
</code></pre>

<p>Looking like this e.g.:</p>

<pre><code>Source: local data frame [5 x 2]
        occ  procras
      (dbl)    (dbl)
    1     0 1.993141
    2     6 2.124020
    3    16 2.251548
    4    28 2.469658
    5    40 2.617903
</code></pre>

<p>With ggplot2 I could now plot the average change over time, and by easily adjusting the group_data() of dplyr I could also get means per sub groups (for instance, the average score per occasion for men and women).
Now I would like to add a column to the mean_data table which includes the length for the 95%-CIs around the average score per occasion.</p>

<p><a href="http://www.cookbook-r.com/Graphs/Plotting_means_and_error_bars_(ggplot2)/" rel="noreferrer">http://www.cookbook-r.com/Graphs/Plotting_means_and_error_bars_(ggplot2)/</a> explains how to get and plot CIs, but this approach seems to become problematic as soon as I wanted to do this for any subgroup, right? So is there a way to let dplyr also include the CI (based on group size, ect.) automatically in the mean_data?
After that it should be fairly easy to plot the new values as CIs into the graphs I hope.
Thank you.</p>
