title: Mean and Confidence interval for Groups of Variable in R
body: <p>I'm new to R and I'm attempting to do something that I believe should be very simple but code online has not helped. </p>
  
  <pre><code>data &lt;- structure(list(Group = c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3), 
  Time = c(1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2), mean_PctPasses = c(68.26, 
  60.2666666666667, 62.05, 66.3833333333333, 59.7333333333333, 
  69.7714285714286, 57.1888888888889, 63.8875, 61.1833333333333, 
  59.775, 66.2666666666667, 62.12), mean_AvgPassing = c(7.3, 
  7.01111111111111, 6.35, 9.26666666666667, 6.68333333333333, 
  8.78571428571429, 5.87777777777778, 8.3125, 7.63333333333333, 
  7.7, 8.38333333333334, 6.89), mean_AvgRush = c(0.3, -0.3, 
  3.5, 0.75, 5, 1.47142857142857, 5.71111111111111, 3.3875, 
  2.74, 6.6, 4.5, 5), mean_Int = c(0.2, 0.777777777777778, 
  0.25, 0.5, 1.5, 0.857142857142857, 0.777777777777778, 0.75, 
  0.666666666666667, 0.75, 0.833333333333333, 1.1), mean_Rate = c(99.3, 
  88.5222222222222, 80.5, 106.45, 77.2333333333333, 102.885714285714, 
  76.8888888888889, 100.075, 92.1166666666667, 78.55, 98.05, 
  79.56)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, 
  -12L), .Names = c("Group", "Time", "mean_PctPasses", "mean_AvgPassing", 
  "mean_AvgRush", "mean_Int", "mean_Rate"))
  </code></pre>
  
  <p>Using this dataset I have 2 grouping variables "Group" and "Time". I would like to get the means and confidence intervals in a table format for each of these combinations for the variables mean_PctPasses to mean_Rate and save the result so it is in a table. I need it to be in a table because I will refer to it later in plotly. Doing this in SPSS is quite easy.</p>
  
  <p>I've attempted several functions and below is issues I've had with each</p>
  
  <pre><code>library(rcompanion)    
  ci.mean(mean_PctPasses~Group+Time, data = data)
  
  library(DescTools)
  MeanCI(data$mean_PctPasses)
  
  library(Rmisc)
  CI(data$mean_PctPasses,    ci=0.95)
  </code></pre>
  
  <p>MeanCI, ci.mean and CI don't allow for multiple variables to be listed and are saved as a table (only shows up in console)</p>
  
  <pre><code>by(data = data, data$Group, FUN = stat.desc)
  </code></pre>
  
  <p>This won't allow me to group my data according to both Group and Time. Below is an example of the graph I hope to build in R (shown in SPSS). </p>
  
  <p><a href="https://i.stack.imgur.com/cYfXv.png" rel="nofollow noreferrer">SPSS Example</a></p>
  
  <p>Any help/assistance on this would be great. Let me know if any clarifications are needed and I'll be sure to edit my initial post.</p>
  
  <p><strong><em>UPDATE</em></strong></p>
  
  <p>After some great answers (thank you Rob and Steven) I felt I needed to clarify my question a little bit. 
  I would like to get statistics for each group (not individually) for all statistics (mean_PctPasses to mean_Rate). An example of a function that produces the stats I would like for one variable is shown below using Rmisc
     library(Rmisc)
     group.UCL(mean_PctPasses~Group+Time , data, FUN=CI)
  This gives me the following output only for mean_PctPasses 
  <a href="https://i.stack.imgur.com/yr6ah.png" rel="nofollow noreferrer">Output Using Rmisc</a></p>
  
  <p>But what I would like to have is the following (which I have photoshopped)
  <a href="https://i.stack.imgur.com/RLSKu.jpg" rel="nofollow noreferrer">Image of Desired Ouput</a></p>
  
  <p>This could, of course, be shown in the other orientation (example below with SPSS and SEM).
  <a href="https://i.stack.imgur.com/0nKWK.png" rel="nofollow noreferrer">Alternative Orientation example in SPSS</a></p>