title: How to assign numeric value to new word within column in R
body: <p>I'm assigning values to a list of fruits like this in R.</p>
  
  <pre><code>#input csv of fruits
  
  fruits
   apple
   pineapple
   orange
   pear
  
  fruits &lt;- data.frame(fruits = c("apple", "pineapple", "orange", "pear"))
  
  mapping &lt;- c("apple" = 1, "orange"= 10, "pear" = 5,"pineapple" = 11)
  
  fruits$value &lt;- mapping[fruits[,1]]
  
  #output
  
  fruits     value
   apple     1
   pineapple 11
   orange    10
   pear      5
  </code></pre>
  
  <p>When the fruit list gets updated, say by adding mango and kiwi, I want any possible unexpected word/text of fruit to be assigned the numeric value of 1 without having to add that specific word to the mapping.</p>
  
  <p>Running the code with new fruits outputs this.</p>
  
  <pre><code>fruits     value
   apple     1
   pineapple NA
   orange    11
   pear      NA
   mango     5
   kiwi      10
  
  fruits2 = data.frame(fruits = 
    c("apple", "pineapple", "orange", "pear", "mango", "kiwi"))
  </code></pre>
  
  <p>I would expect the NA to be with mango and kiwi but they are not.</p>
  
  <p>How to do I assign the value 1 to new fruits not included in the original mapping?</p>
  
  <p>Thanks</p>