title: Transform DF Column Values to Matrix in R
body: <p>I want to count unique values of categorical variable based of a column based on Date.</p>
  <p>I want result as a matrix where column names are the values categorical variable, row names will be unique Date values and their cell values is the unique count.</p>
  <p>The below links solves the group by problem but I am looking for the transformed df:</p>
  <p><a href="https://stackoverflow.com/questions/17421776/how-to-add-count-of-unique-values-by-group-to-r-data-frame/17421925#17421925">How to add count of unique values by group to R data.frame</a></p>
  <p><a href="https://stackoverflow.com/questions/44910829/r-extract-unique-values-in-one-column-grouped-by-values-in-another-column">R: Extract unique values in one column grouped by values in another column</a></p>
  <p>My df has more than 50,000 rows and looks like:</p>
  <pre><code>dat &lt;- data.frame(Date = c('06/08/2018','06/08/2018','07/08/2018','07/08/2018','08/08/2018','09/08/2018','09/08/2018','11/08/2018','11/08/2018','13/08/2018'),
                    Type= c('A','B','C','A','B','A','A','B','C','C'))
  </code></pre>
  <p>I want my resultant matrix to have &quot;A&quot;, &quot;B&quot; ,&quot;C&quot; as new columns, &quot;Date&quot; as the rows and values in matrix as the unique count, shown in below image:</p>
  <p><a href="https://i.stack.imgur.com/yQLSK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yQLSK.png" alt="Resultant Matrix" /></a></p>
  <p>Also, it would be great that we don't hardcode categorical values. So, in future if instead of 3 it becomes 4, then code automatically handles it.</p>