title: R split factor to m-columns with original length
body: <p>Suppose I have a factor (in a data.frame) which represents years:</p>
  
  <pre><code>  year
  1 2012
  2 2012
  3 2012
  4 2013
  5 2013
  6 2013
  7 2014
  8 2014
  9 2014
  </code></pre>
  
  <p>I would to to create (in this case) three new columns in the data.frame and end up with:</p>
  
  <pre><code>  y2012 y2013 y2014
  1     1     0     0
  2     1     0     0
  3     1     0     0
  4     0     1     0
  5     0     1     0
  6     0     1     0
  7     0     0     1
  8     0     0     1
  9     0     0     1
  </code></pre>
  
  <p>I can of course write a bunch of ifelse-statements, but that seems very unhandy.</p>