title: Lagging Variables in R
body: <p>What is the most efficient way to make a matrix of lagged variables in R for an arbitrary variable (i.e. not a regular time series)</p>
  
  <p>For example:</p>
  
  <p><strong><em>Input</em></strong>:</p>
  
  <pre><code>x &lt;- c(1,2,3,4) 
  </code></pre>
  
  <p><strong><em>2 lags, output</em></strong>:</p>
  
  <pre><code>[1,NA, NA]
  [2, 1, NA]
  [3, 2,  1]
  [4, 3,  2]
  </code></pre>