title: Convert a vector into logical matrix
body: <p>Is there a native R function that will take an input vector and return the corresponding binary matrix where the matrix has the same number of columns as unique values in the input vector?</p>
  
  <p>For example, given <code>x &lt;- 1:3</code>, I want to return the following matrix:</p>
  
  <pre><code>     [,1] [,2] [,3]
  [1,]    1    0    0
  [2,]    0    1    0
  [3,]    0    0    1
  </code></pre>
  
  <p>The functions <code>contrasts</code> gets close, but I can't seem to get around the n-1 columns returned:</p>
  
  <pre><code>&gt; contrasts(as.factor(x))
    2 3
  1 0 0
  2 1 0
  3 0 1
  </code></pre>