0

I'm trying to pull data from googlemaps with googleway library.I used Google Elevation API in apply R function


Requests <- apply(df, 1, function(x){

                     google_elevation(df_locations =x[c("lat", "lon")],
                     location_type = "individual",
                     key = key,
                     simplify = TRUE)
})

but I get the following error

df_locations should be a data.frame containing at least two columns of lat and lon coordinates

What am i doing wrong with selecting df columns in function?

Thanks

Denmla
  • 135
  • 1
  • 8
  • It's not the selection, but inside an apply, the "x" is a vector. As your input requires a dataframe, you can do df_locations = data.frame(x[c("lat", "lon")]....) ? – StupidWolf Feb 15 '20 at 17:16
  • 3
    Can't you just use `df` directly in `google_elevation` without the `apply` function? – Allan Cameron Feb 15 '20 at 17:17
  • 2
    I am not familiar with google_elevation.. can you just pass it the whole data frame ? i.e df[,c("lat","lon")] ? – StupidWolf Feb 15 '20 at 17:17
  • You don't need the `apply`, you can use the `df` directly. The examples for `?google_elevation` show you how to use a `data.frame` as the input. – SymbolixAU Feb 17 '20 at 01:49
  • 1
    Thank you very much. I have solved it. No loop was needed. You are right. – Denmla Feb 18 '20 at 08:56

0 Answers0