title: R: Calculate the mean value of a variable by unique values of another variable in a dataframe?
body: <p>I am new to R. I have a data frame that looks like this:</p>
  
  <pre><code>Pupil ID     State      GPA
  1            FL         3.9
  2            TX         3.2
  3            NY         2.2
  4            AK         3.0
  5            CO         2.4
  </code></pre>
  
  <p>... etc. What I would like to do is create a new data frame that looks like this:</p>
  
  <pre><code>State        Mean GPA     Number of pupils 
  AL           2.91         23
  AK           3.23         24
  </code></pre>
  
  <p>and so on. In other words, I'd like to find the unique values for state, and calculate the mean GPA for each one and number of pupils for each one. </p>
  
  <p>Is this possible in R? I know I can do <code>table(data$State)</code> to get the unique states and number of pupils, but I don't know how to calculate the mean for the unique values of state. </p>