title: Regular expressions in R to erase all characters after the first space?
body: <p>I have data in R that can look like this:</p>
  
  <pre><code>USDZAR Curncy
  R157 Govt
  SPX Index
  </code></pre>
  
  <p>In other words, one word, in this case a Bloomberg security identifier, followed by another word, which is the security class, separated by a space. I want to strip out the class and the space to get to:</p>
  
  <pre><code>USDZAR
  R157
  SPX
  </code></pre>
  
  <p>What's the most efficient way of doing this in R? Is it regular expressions or must I do something as I would in MS Excel using the mid and find commands? eg in Excel I would say:</p>
  
  <pre><code>=MID(@REF, 1, FIND(" ", @REF, 1)-1)
  </code></pre>
  
  <p>which means return a substring starting at character 1, and ending at the character number of the first space (less 1 to erase the actual space). </p>
  
  <p>Do I need to do something similar in R (in which case, what is the equivalent), or can regular expressions help here? Thanks.</p>