title: choose the best one, second one,and third
body: <p>there are two columns in a data frame, rank,pet, in the rank column, the most highest rank is "1", the second one is"2", the third one is "10".How do I create a new column b to choose the highest rank within three kinds of pets.For example, in the dog row, I would like to choose first row dog, in the cat row, I would like to choose sixth row cat.</p>
  
  <pre><code>rank&lt;-c(1,2,7,3,10,2,10,2,1)
  pet &lt;-c("dog","dog","dog","cat","cat","cat","bird","bird","bird")
  a &lt;-data.frame(rank,pet)
  </code></pre>