title: ifelse with substring R
body: <p>This feels like it should be an easy question, but I have looked here and other places and can't find a simple answer.</p>
  
  <p>I have survey responses and I need to create a 1/0 dummy for source of the response. I am trying to create a simple flag variable by looking through all data in the comment field, and if the substring matches, flag it 1. </p>
  
  <p>Data EG</p>
  
  <pre><code>ID     comment
  1      rubber chickens
  2      180107 RG - email taken from 2017 graduate survey
  </code></pre>
  
  <p>I need R to look through the comment field, and anytime it sees the phrase 'graduate survey' to code my grad_svy field as 1, otherwise 0.</p>
  
  <p>When I write </p>
  
  <pre><code>data$grad_svy &lt;- ifelse((substr(data$comment,34,49) == "graduate survey"),1,0) 
  </code></pre>
  
  <p>It'll run, but it doesn't mark anything as a 1, when in fact there are hundreds of places it should be marking a 1. I know the two letter phrase begins at 34, and ends at 49, for every instance in the field. I am not sure what I'm not doing, the FAQ for ifelse and substring have been pretty unhelpful.</p>