Reshaping data with R : <p>I have my data in the below table structure:</p>

<pre>   
Person ID | Role | Role Count
-----------------------------
1         | A    | 24
1         | B    | 3
2         | A    | 15 
2         | B    | 4
2         | C    | 7
</pre>

<p>I would like to reshape this so that there is one row for each Person ID, A column for each distinct role (e.g. A,B,C) and then the Role Count for each person as the values. Using the above data the output would be:</p>

<pre>   
Person ID | Role A | Role B | Role C
-------------------------------------
1         |    24  |   3    |   0
2         |    16  |   4    |   7
</pre>

<p>Coming from a Java background I would take an iterative approach to this:</p>

<ol>
<li>Find all distinct values for Role </li>
<li>Create a new table with a column for PersonID and each of the distinct roles </li>
<li>Iterate through the first table, get role counts for each Person ID and Role combination and insert results into new table.</li>
</ol>

<p>Is there another way of doing this in R without iterating through the first table? </p>

<p>Thanks</p>
