title: Aggregate dataframe into a frequency table
body: <p>I am looking to reshape a dataframe from something which looks like this, with variables: </p>
  
  <pre><code>Year, University, Degree, Gender 
  </code></pre>
  
  <p>With each row depicting an entry of a student, eg:</p>
  
  <pre><code>2017, University College London, Social Science, Male 
  
  2017, University of Leeds, Social science, Non-Binary 
  </code></pre>
  
  <p>I would like to create a frequency table from this data in order to condense the number of rows so that for each university, there are 19 rows for each of the degree categories, and then for each Degree, the count/frequency for each gender is shown, which would look something like this.</p>
  
  <pre><code>Year University Degree [Gender (Male, Female, Non-Binary)]
  
  2017 UCL Biological Sciences 1 0 2  
  </code></pre>
  
  <p>I hope this makes sense. Thank you for the help.</p>
  
  <p>EDIT: 
  I would now like to be able to plot this data as a line graph using a subset of the data. I am currently subsetting outside of the plotting function like so </p>
  
  <pre><code>   subsetucl &lt;- TFtab[which(TFtab$University == 'University College London'),]
  ggplot(data=subsetucl, aes(x=Year, y=Female, group=Degree, color = Degree)) + geom_line()+ geom_point(size = 0.8) + xlab("Year of application") + ylab("Frequnecy of Females") + ggtitle("UCL Applications by Degree (2011-2017)") + theme_bw()
  </code></pre>
  
  <p>What is the best way to subset the data within the plotting function and how do I best display lines for all Genders rather than just female frequencies. 
  Thank you </p>