title: Selecting an ID based on hierarchical criteria
body: <p>Helo there. I have a group of patients diagnosed with a certain disease (but with different criteria) at different dates, as follows:</p>
  
  <pre class="lang-r prettyprint-override"><code>ID1 = c(12,14,56)
  Date_ID1 = c(20160209,20120101, 20170227)
  Criteria_1 = c("B","C","A")
  
  ID2 = c(NA,43,22)
  Date_ID2 = c(NA,20160710,20170227)
  Criteria_2 = c(NA,"B","B")
  
  ID3 = c(96,41,123)
  Date_ID3 = c(20170227,20120101,20160601)
  Criteria_3 = c("A","B","A") 
  
  test = data.frame(ID1, Criteria_1,Date_ID1,ID2, Criteria_2,Date_ID2,ID3,Criteria_3,Date_ID3)
  </code></pre>
  
  <p>Each row represent the same patient, a new ID ascribed at every exam.
  What I need is to select one ID per row based on a hierarchical criteria (A>B>C); in case of ties, the select ID should correspond to the earliest date of that diagnosis. The output is expected to look like this:</p>
  
  <pre class="lang-r prettyprint-override"><code>cbind(test,data.frame(Selected_ID = c(96,41,123)) )
  </code></pre>
  
  <p>Any suggestions are very welcome.</p>