title: R An if else statement inside a for loop
body: <p>I have a data table made of 3 columns that is assigned to a variable g. </p>
  
  <pre><code>g
  #      V1   V2 V3
  # [1,]  1  Yes  3
  # [2,]  4   No  6
  # [3,]  7   No  9
  # ...
  </code></pre>
  
  <p>I'm trying to create a list, m, by checking to see if the values in g[,2] are "Yes" or "No", and then pasting some string into m. </p>
  
  <pre><code>m &lt;- for(i in 1:nrow(g)){
    if(g[i,2]=='No'){
      paste0("ABC", g[i,1], "DEF", g[i,2], "GHI", g[i,3],"\n")
    } else if(g[i,2]=='Yes'){
      paste0("GHI", g[i,1], "DEF", g[i,2], "ABC", g[i,3],"\n")
    } else {NULL}
  }
  
  m
  # NULL
  </code></pre>
  
  <p>However when I try to return m, it just returns NULL. I want m to look like this:</p>
  
  <pre><code>m
  # ABC1DEFYesGHI3
  # GHI2DEFNoABC9
  </code></pre>
  
  <p>Can someone point out what I am doing wrong here? Thank you very much!</p>