title: sort column by variable name then loop in each variable
body: <p>I am an R noob :) and this is my first post.
  I have a dataset of 4k entries (<code>data</code>) describing mortality rates (<code>data$mortality</code>) by US state (<code>data$state</code>).</p>
  
  <p>I want to loop through the mortality rates by state name 
  for instance loop through all mortality rates in <code>"AK"</code>
  something like this: </p>
  
  <pre><code>tbl &lt;- table (data$State) ## table with frequency for entries at each state 
  </code></pre>
  
  <p>How can I loop through all the occurrences of each state?</p>
  
  <p>I don't want to specify the state name. I want to sort all states then loop through them by name:
  <code>"AK"</code>, <code>"AL"</code> etc...</p>
  
  <p>for instance, my table would be:</p>
  
  <pre><code>State   mortality 
  AL  14.3
  AL  18.5
  AL  18.1
  AL  NA
  AL  NA
  AK  NA
  AK  17.7
  AK  18
  AK  15.9
  AK  NA
  AK  19.6
  AK  17.3
  AZ  15
  AZ  17.1
  AZ  17.1
  AZ  NA
  AZ  16.4
  AZ  15.2
  AZ  16.7
  </code></pre>
  
  <p>I can then loop through all rates in "AL" and rank them then choose a hospital name associated with each ranked mortality rate in "AL"
  I can write a piece of code for each state at a time but imagine doing that for all states!</p>