title: R-Geocoding with Address
body: <p>I have 32K lines of addresses for which I have to find long/latitude values. </p>
  
  <p>I'm using the code found <a href="http://www.storybench.org/geocode-csv-addresses-r/" rel="nofollow noreferrer">here</a>. I'm so very thankful for this person to creating it but I have a question:</p>
  
  <p>I'd like to edit it so that if the loop runs into an issue with the current row's address, it simply states NA in the Lat/Long fields and moves to the next one. Does anyone know how that may be accomplished? The code is below:</p>
  
  <pre><code># Geocoding a csv column of "addresses" in R
  
  #load ggmap
  library(ggmap)
  
  # Select the file from the file chooser
  fileToLoad &lt;- file.choose(new = TRUE)
  
  # Read in the CSV data and store it in a variable 
  origAddress &lt;- read.csv(fileToLoad, stringsAsFactors = FALSE)
  
  # Initialize the data frame
  geocoded &lt;- data.frame(stringsAsFactors = FALSE)
  
  # Loop through the addresses to get the latitude and longitude of each address and add it to the
  # origAddress data frame in new columns lat and lon
  for(i in 1:nrow(origAddress))
  {
    # Print("Working...")
    result &lt;- geocode(origAddress$addresses[i], output = "latlona", source = "google")
    origAddress$lon[i] &lt;- as.numeric(result[1])
    origAddress$lat[i] &lt;- as.numeric(result[2])
    origAddress$geoAddress[i] &lt;- as.character(result[3])
  }
  # Write a CSV file containing origAddress to the working directory
  write.csv(origAddress, "geocoded.csv", row.names=FALSE)
  </code></pre>