title: Aggregate data based on a categorical variable
body: <p>I am trying to calculate mean salary for every job title from a data set which has 2159 job titles and convert into a list. My code</p>
  
  <pre><code>&gt; for (i in 1:length(unique(sfs$JobTitle))) {
    a&lt;-print(paste((sfs$JobTitle[[i]])))
    b&lt;-print(paste((mean(sfs$BasePay[[i]]))))
    ms&lt;-list(a,b)
  }
  </code></pre>
  
  <p>Also tried</p>
  
  <blockquote>
  <pre><code>for (i in 1:length(unique(sfs$JobTitle))) {   ms&lt;-matrix((sfs$JobTitle[[i]]),(mean(sfs$BasePay[[i]]))) }
  </code></pre>
  </blockquote>
  
  <p>The output I am getting is a list of 2 elements only. Can you guys help. Thanks</p>