title: Creating a pivot table based on categorical variables
body: <p>I am currently doing some analysis in R and can't seem to find a working solution to the following problem: </p>
  
  <p>My raw data is a table containing 3 columns: "user id", "year" and "block". 
  The block column can either have a value 'north', 'east', 'south', 'west' or 'other'. </p>
  
  <p><a href="https://i.stack.imgur.com/rJnXp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rJnXp.png" alt="Raw data"></a></p>
  
  <p>What i want to creat now is some sort of pivot table (not sure if this is the right term to use here). This table should consist of a single row for each combination of user_id and year followed by 5 new columns containing a dummy variable referencing whether or not the customer was sitting in the respective block that year or not. Similar to the example below: </p>
  
  <p><a href="https://i.stack.imgur.com/SDQrl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SDQrl.png" alt="How the result should look like"></a></p>
  
  <p>I have been trying to get things working through the use of the reshape package in R but it seems to struggle handling the categorical variable "block". 
  Any tips/help is greatly appreciated! </p>
  
  <p>Thanks in advance</p>