I have the following data frame of long/lat points (points
):
GPSLatitude GPSLongitude
1 40.66126 22.89565
2 40.66127 22.89565
3 40.66128 22.89565
4 40.66130 22.89566
5 40.66131 22.89567
6 40.66132 22.89569
7 40.66134 22.89573
8 40.66136 22.89577
9 40.66137 22.89582
10 40.66141 22.89594
11 40.66142 22.89601
12 40.66145 22.89609
13 40.66147 22.89618
14 40.66150 22.89627
15 40.66152 22.89635
16 40.66155 22.89644
17 40.66160 22.89650
18 40.66165 22.89654
19 40.66172 22.89656
20 40.66178 22.89658
21 40.66186 22.89659
22 40.66193 22.89660
23 40.66200 22.89662
24 40.66207 22.89663
25 40.66213 22.89664
26 40.66218 22.89665
27 40.66223 22.89665
28 40.66227 22.89664
29 40.66230 22.89663
30 40.66234 22.89662
31 40.66238 22.89661
32 40.66242 22.89662
33 40.66244 22.89664
34 40.66245 22.89666
35 40.66247 22.89669
36 40.66248 22.89671
37 40.66249 22.89673
38 40.66250 22.89674
39 40.66251 22.89676
40 40.66253 22.89679
41 40.66255 22.89683
42 40.66257 22.89686
43 40.66261 22.89694
44 40.66263 22.89698
45 40.66265 22.89700
46 40.66267 22.89702
47 40.66268 22.89705
48 40.66270 22.89707
49 40.66272 22.89709
and the following reference point (point17
):
22.89704,40.66265
I want to split - apply the dist_google()
per 25 rows because dist_google
function can be applied up to 25 pairs of origin - destination. Finally, I want to combine the results in a new data frame. I have tried to do it with a simple for loop
:
for (i in 1:nrow(points)) {
myresults[i,]<- dist_google(from = point17, to = points[i,], mode = "driving", google_api = "my_api_key")
but it takes time to calculate the results. So I decided to split the data frame per 25 rows and apply the function (this solution calculates the results instantly). I've tried the adply()
function of plyr
package:
adply(points17, 25, dist_google(from = pointLC17, to = points17[i,], mode = "driving", google_api = "my_api_key"))
but I had an error with the .margins
argument of the adply(). Any ideas to solve this problem?
Thank you in advance!