title: R how to implement if else in apply instead of for loop
body: <p>EX Data:</p>
  
  <pre><code>Col1 Col2 
     1    a
     2    b
     3 null
     4    c
  </code></pre>
  
  <p>How do I change all elements of <code>Col2</code> that are <code>NULL</code> to some predefined value. My actual data is about 250,000 rows so a <code>for</code> loop would take too much time. I was thinking about some kind of <code>apply</code> / <code>ddply</code> and <code>ifelse</code> combination but I can't seem to get it working.</p>
  
  <p>More specifically, how do I change the for loop to something more efficient</p>
  
  <pre><code>for(I in 1:n)
  {
    if(col2(I) == NULL)
      col2(I) = x
      else...nothing happens
  }
  </code></pre>