How to update only missing values in R based on parameters

r

#1

I have data set as below mentioned script

library(ggmap)
countries <- c('Ghana', 'Guinea', 'Mali', 'Niger')
withLocation<- data.frame(countries, geocode(countries))

once I run the command then I get data like this

       countries        lon        lat
1          Ghana  -1.023194   7.946527
2         Guinea  -9.696645   9.945587
3           Mali  -3.996166  17.570692
4          Niger         NA         NA

Now I have missing values for ‘Niger’ and want to update that row only as running the google API with complete list will miss different country, please help me to achieve this


#2

Unable to clearly understand your question. Are you asking easiest way to manually populate those two NA values?


#3

image
First of all Niger is working
second you can do a condition check for lon, lat where values are equal to NA and call google API to geo code it, neglecting the country names which are already geo coded correctly