title: add column values based on other columns in data frame using for and if
body: <p>I have a dataframe like this:</p>
  
  <pre><code>     id        adit     diag1   diag2       
        2       3         4230    2234        
        3       5         3345    4456        
        4       6         4567    4467
  </code></pre>
  
  <p>I would like to add other 2 columns, <code>dse1</code> and <code>dse2</code> using the pseudo-code below:</p>
  
  <pre><code>if diag1 contains 4230 then dse1 = 1 else dse1 = 0
  
  if diag2 contains 4567 then dse2 =1  else dse2 = 0
  </code></pre>
  
  <p>I used this:</p>
  
  <pre><code>for (i in 1 : nrow(dse)){
    for (j in 3: ncol(dse)){
       if dse[i,j] %in% ("4320"){dse$dse1 = 1}
          else{dse$dse1 = 0}
      if dse[i,j] %in% ("4567"){dse$dse2 = 1}
          else{dse$dse2 = 0} 
    }
  }
  </code></pre>
  
  <p>But these do not work.</p>