title: For loop in R - error in if - missing value where TRUE/False needed
body: <p>I am working on a project for personal development. I have never used R before so i am struggling a bit. 
  I would like to get Longitude and Latitude based on a location. the script works fine until it gets NA value.
  I have tried to use <code>if</code>, <code>tryCatch</code>, <code>is.na</code> and many other functions but nothing works.  </p>
  
  <p>The aim is, I get latitude and longitude based on Location. Many values are missing in this csv file. So I need something that can avoid <code>NA</code> values. Is there any other way to get there ?
  Thanks</p>
  
  <pre><code>library(ggmap)
  
  for(i in 1:nrow(MassShooting)){
  
      Data &lt;- geocode(MassShooting$Location[i], output = "latlona", source = "google")
  
                  MassShooting$Longitude[i] &lt;- as.numeric(Data[1])
                  MassShooting$Latitude[i] &lt;- as.numeric(Data{2])
  }
  </code></pre>
  
  <p>Here is my table(it contains around 400 rows):
  <a href="https://i.stack.imgur.com/KMfmp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KMfmp.png" alt="enter image description here"></a></p>
  
  <p>Solved : Here is the code i used :</p>
  
  <pre><code>for(i in 1:nrow(data1))
  {
      ifelse(is.na(data1$Location[i]), NA,      
      result2 &lt;- geocode(data1$Location[i], output = "latlona", source = "google"))
            data1$Longitude[i] &lt;- as.numeric(result2[1])
            data1$Latitude[i] &lt;- as.numeric(result2[2])
  
  }
  </code></pre>