title: ifelse not working in R
body: <p>I have the following variables:</p>
  
  <pre><code>a              
  welcome       
  put to
  look at
  sorted for
  </code></pre>
  
  <p>I want to search strings in:</p>
  
  <pre><code>if have string "come" then b="home"
  if have string "to" then b="where"
  if have string "sorted" then b="done"
  if have string "look" then b="great"
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>a              b
  welcome        home      
  put to         where
  look at        great
  sorted for     done
  </code></pre>
  
  <p>I tried below code.</p>
  
  <pre><code>let$b &lt;- ifelse(grepl("come", let$a), "home",
           ifelse(grepl("to", let$a), "where", 
           ifelse(grepl("sorted", let$a), "done",
           ifelse(grepl("look", let$a), "great","")))
  </code></pre>
  
  <p>The code above is not working properly.</p>