0

i have missing latitude and longitude and I need to compute the latitude and longitude from location variable but this doesn't work

the code work if I don't apply the geocode function but doesn't work with the function

can somebody help me?

us_mass_shooting_data %>% mutate(
    Latitude = ifelse(
    is.na(Latitude), geocode(Location)$lat, Latitude),
    Longitude = ifelse(
    is.na(Longitude), geocode(Location)$lon, Longitude 
  )
)
  • Hi benActor. Welcome to StackOverflow! Please read the info about [how to ask a good question](https://stackoverflow.com/help/how-to-ask) and how to give a [minimale reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610). That way you can help others to help you! As the question stands now we do not know what `geocode` is or does and more importantly we **can't** reproduce your error... – dario Feb 26 '20 at 11:50
  • I believe this is possible in library(geonames) – Dr. Flow Feb 26 '20 at 11:57
  • I suggest that you first run `geocode(us_mass_shooting_data$Location)` and then use the output. Because it is most probably an API call and not a function, avoid using it multiple times. – Rohit Feb 26 '20 at 12:07

0 Answers0