title: String Conversion in R based on SAS
body: <p>How do I find the position of the first occurrence of a character string in a dataframe column?</p>
  <p>This is to convert the following SAS code to R:</p>
  <pre><code>AVAL = INPUT(SUBSTR(AVALC,INDEX(AVALC,&quot;- &quot;)+2,1),8.);
  </code></pre>
  <p>This is a sample of the data:</p>
  <pre><code>AVALC
  
  7
  
  4
  
  EXTREME DIFFICULTY - 4
  
  STOPPED DOING THIS FOR OTHER REASONS OR NOT INTERESTED IN DOING THIS - 6
  
  A LITTLE DIFFICULTY - 2
  
  MODERATE DIFFICULTY - 3
  
  NO DIFFICULTY AT ALL - 1
  
  MODERATE DIFFICULTY - 3
  
  NO DIFFICULTY AT ALL - 1
  
  SOME OF THE TIME - 3
  
  SOME OF THE TIME - 3
  
  MOSTLY FALSE - 4
  
  DEFINITELY FALSE - 5
  
  GOOD - 3
  
  FAIR - 3
  
  SOME OF THE TIME - 3
  
  NONE - 1
  </code></pre>
  <p>Some values can be converted directly to numeric values (done), extracting the numbers to a numeric field from the &quot;-&quot; responses is what I am trying to do.</p>