title: R for loop ignores conditional if statement
body: <p>I'm working with a dataset in which I need R to skip over it if the value is NOT missing. I've tried making a for loop, but R ignores my logic. I've seen other for loop posts, but they do not involve the conditional being ignored.</p>
  
  <p>Here's a sample dataset:</p>
  
  <pre><code>library(dplyr)
    my_problem &lt;- tibble(name = c("Joe", "Joseph", "Joey"),
                         score1 = c(2, 7, 12),
                         score2 = c(NA, 5, 10))
  </code></pre>
  
  <p>Here's what I want it to look like:</p>
  
  <pre><code>solution &lt;- tibble(name = c("Joe", "Joseph", "Joey"),
                       score1 = c(1, 7, 12),
                       score2 = c(NA, 5, 10),
                       score2edit = c(.30103, 5, 10))
  </code></pre>
  
  <p>And here's my for loop with a log10() transformation on score1 if the score2 column is NA. However, for some reason, the code ignores my if statement and jumps straight to the else.</p>
  
  <pre><code>  for(i in 1:nrow(my_problem)) {
      if(is.na(my_problem$score2[i])) {
        my_problem$score2edit &lt;- log10(my_problem$score1)
      } else {
        my_problem$score2edit &lt;- my_problem$score2
      }
    }
  </code></pre>
  
  <p>Thank you! If you could also explain why this loop isn't working, it would be very helpful. </p>