title: Consolidating similar (but not equal) rows and counting the differing categorical variable in R
body: <p>I have the following the following data frame (‘mydf’):</p>
  
  <pre><code>ID   Type   Count  Mark
  U1     A     50     R1
  U1     A     50     R3
  U1     A     50     R4
  U1     A     50     R3
  U2     B     24     R2
  U2     B     24     R5
  U3     A     88     R1
  </code></pre>
  
  <p>Each row contains 4 variables:</p>
  
  <ul>
  <li><p><strong>ID</strong>: the user’s ID.</p></li>
  <li><p><strong>Type</strong>: the user’s type, which is <em>categorical</em> and consistent for all rows with that ID.</p></li>
  <li><p><strong>Count</strong>: the user’s count, which is <em>continuous</em> and consistent for all rows with that ID.</p></li>
  <li><p><strong>Mark</strong>: one of 15 <em>categorical</em> symbols, which may vary between different
  rows with the same ID.</p></li>
  </ul>
  
  <p>Presently, there is one row for each mark which appears, so that there are multiple rows per ID. </p>
  
  <p>The number of marks is different for different IDs (anything from 4-50).</p>
  
  <p>What I a need to do:</p>
  
  <ol>
  <li><p>Consolidate rows with the same ID into a single row, which contains all the consistent information (Type/Count), as well as a listing (or count) of all the marks which appear for that ID. This listing needs to reflect how often each mark appears for that ID (for example, if the same mark appears twice for a single ID, this needs to be reflected, as happens for U1 in rows 2 and 4).</p></li>
  <li><p>Get a count of the number of time each mark appears for each ID.</p></li>
  <li><p>Get a count of the total number of marks for each ID.</p></li>
  </ol>
  
  <p>Listing of the marks for each ID is not necessary as long as the counts described in 2 and 3 exist (see for example the expected output below).</p>
  
  <p><strong>Expected output (approximately)</strong>:</p>
  
  <pre><code>ID   Type   Count  Mark_R1 Mark_R2 Mark_R3 Mark_R4 Mark_R5 Mark_Total
  U1     A     50       1       0       2       1       0       3
  U2     B     24       0       1       0       0       1       2
  U3     A     88       1       0       0       0       0       1
  </code></pre>
  
  <p>Thank you for your help!</p>