title: Create new variable based on the order of values in other columns
body: <p>I have a data frame relative to accesses to a website. Several accesses per day, with different possible actions and descriptions of the actions</p>
  
  <pre><code>People | Date       | Time  | Action | Descr  | 
         |            |       |        |        | 
  j      | 01/01/2010 | 10:13 | X      | A      | 
  j      | 01/01/2010 | 10:15 | Y      | B      | 
  j      | 02/01/2010 | 14:15 | Z      | C      | 
  j      | 03/01/2010 | 11:45 | X      | D      | 
  j      | 03/01/2010 | 13:56 | X      | E      | 
  j      | 03/01/2010 | 18:43 | Z      | F      | 
  j      | 03/01/2010 | 18:44 | X      | A      | 
  </code></pre>
  
  <p>After reducing the data frame to a balanced daily panel data, I need to create variables such that:</p>
  
  <p>-the value of the first variable (FirstX) must be equal to the description (Descr) of the first Action = X of the day (if available) and zero otherwise</p>
  
  <p>-the value of the second variable must be equal to the description of the second Action = X of the day and zero otherwise</p>
  
  <p>-so on</p>
  
  <p>Once I transformed it into a balanced daily panel (which I can do) I need to have a final result which looks like this:</p>
  
  <pre><code>People | Date       |Accesses| First X|Second X| Third X| Fourth X |
         |            |        |        |        |        |          |
  j      | 01/01/2010 |    2   |   A    |   0    |    0   |    0     |
  j      | 02/01/2010 |    1   |   0    |   0    |    0   |    0     |
  j      | 03/01/2010 |    4   |   D    |   E    |    A   |    0     |
  </code></pre>