title: Create mutually exclusive dummy variables from categorical variable in R
body: <p>A while ago, I asked a question about creating a categorical variable from <a href="https://stackoverflow.com/questions/16135316/creating-categorical-variables-from-mutually-exclusive-dummy-variables">mutually exclusive dummy variables</a>. Now, it turns out I want to do the opposite.</p>
  
  <p>How would one go about creating dummy variables in a long-form dataset from a single categorical variable (<code>time</code>)? e.g. the dataframe below...</p>
  
  <pre><code>id     time   
  1      1       
  1      2       
  1      3      
  1      4       
  </code></pre>
  
  <p>would become...</p>
  
  <pre><code>id     time    time_dummy_1   time_dummy_2    time_dummy_3  time_dummy_4
  1      1       1              0               0             0
  1      2       0              1               0             0
  1      3       0              0               1             0
  1      4       0              0               0             1
  </code></pre>
  
  <p>I'm sure this is trivial (and please let me know if this question is a duplicate -- I'm not sure it is, but will happily remove if so). Thanks!</p>