title: Creating Identity Matrices in R
body: <p>I'd like to create identity matrices of different sizes, and I'm able to do so on a smaller scale like so:</p>
  
  <pre><code>&gt; x &lt;- matrix(cbind(c(1,0), c(0,1)), 2)
  &gt; x
       [,1] [,2]
  [1,]    1    0
  [2,]    0    1
  </code></pre>
  
  <p>And like so:</p>
  
  <pre><code>&gt; y &lt;- matrix(cbind(c(1,0,0), c(0,1,0), c(0,0,1)), 3)
  &gt; y
       [,1] [,2] [,3]
  [1,]    1    0    0
  [2,]    0    1    0
  [3,]    0    0    1
  </code></pre>
  
  <p>However, it seems this will become increasingly tedious as identity matrices increase in size.</p>
  
  <p><img src="https://i.stack.imgur.com/XstUg.png" alt="enter image description here"></p>
  
  <p>Is there an easier way to create <em>n</em>-value identity matrices?</p>