title: Coalescing/merging rows but retaining "dominant" values
body: <p>My problem seems rather trivial but appearantly I didn't come up with the appropriate search terms.</p>
  <p>My data is like this:</p>
  <pre><code>data &lt;- data.frame(ID = c(1,1,2,3,3),
                     V1 = c(&quot;A&quot;,&quot;B&quot;,&quot;A&quot;,&quot;B&quot;,&quot;C&quot;),
                     V2 = c(&quot;C&quot;,&quot;B&quot;,NA,&quot;B&quot;,&quot;A&quot;),
                     V3 = c(&quot;A&quot;,&quot;B&quot;,&quot;C&quot;,&quot;B&quot;,NA))
  </code></pre>
  <p>I want to coalesce or merge the rows by ID and keep only one row per ID with the &quot;highest&quot; value in each column. In my example, I would like to prioritize C over B over A.</p>
  <p>After the desired operation, my data would look like this:</p>
  <pre><code>| ID | V1 | V2 | V3 |
  | -- | -- | -- | -- |
  |  1 | B  | C  | B  |
  |  2 | A  | NA | C  |
  |  3 | C  | B  | B  |
  </code></pre>
  <p>Any hints would be greatly appreciated! Dplyr is preferred, but no necessity. Thanks!</p>
  <p>Edit: The solutions (thank you for that!) all took advantage of the fact that letters are &quot;ordered&quot; in R.</p>
  <p>Let us take this example data:</p>
  <pre><code>data &lt;- data.frame(ID = c(1,1,2,3,3),
                     V1 = c(&quot;yes&quot;,&quot;no&quot;,&quot;yes&quot;,&quot;no&quot;,&quot;unsure&quot;),
                     V2 = c(&quot;unsure&quot;,&quot;no&quot;,NA,&quot;no&quot;,&quot;yes&quot;),
                     V3 = c(&quot;yes&quot;,&quot;no&quot;,&quot;unsure&quot;,&quot;no&quot;,NA))
  </code></pre>
  <p>Where the desired outcome is that the priority is &quot;yes&quot; over &quot;no&quot; over &quot;unsure&quot;.</p>