title: Extract the first (or last) n characters of a string
body: <p>I want to extract the first (or last) <em>n</em> characters of a string. This would be the equivalent to Excel's <code>LEFT()</code> and <code>RIGHT()</code>. A small example:</p>
  
  <pre><code># create a string
  a &lt;- paste('left', 'right', sep = '')
  a
  # [1] "leftright"
  </code></pre>
  
  <p>I would like to produce <code>b</code>, a string which is equal to the first 4 letters of <code>a</code>:</p>
  
  <pre><code>b
  # [1] "left"
  </code></pre>
  
  <p>What should I do?</p>