title: Creating a new variable from a lookup table
body: <p>I have the following columns in my data set:</p>
  
  <pre><code>presult     aresult
    I         single
    I         double
    I         triple
    I         home run
    SS        strikeout
  </code></pre>
  
  <p>I would like to add a third column "bases" that is dependent upon the value of the result in column aresult.</p>
  
  <p>For example, I would like bases to be 1 for a single, 2 for a double, 3 for a triple, 4 for a home run, and 0 for a strikeout.</p>
  
  <p>Usually I would create the new variable like this:</p>
  
  <pre><code>dataset$base&lt;-ifelse(dataset$aresult=="single", 1, 0)
  </code></pre>
  
  <p>The problem is that I don't know how to code the new variable in without setting all other variables to zero.</p>