我是stplanr软件包的初学者。由于dist_google函数最多可应用25对起点(目的地),因此,我已分割了一个大数据框,每25行包含长点/纬度点。因此,这是原始的大数据框:
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
50 40.66273 22.89710
51 40.66274 22.89711
52 40.66275 22.89712
53 40.66275 22.89714
54 40.66276 22.89716
55 40.66276 22.89718
56 40.66276 22.89721
57 40.66275 22.89725
58 40.66273 22.89728
然后,我使用以下命令每25行拆分此数据帧:
pointssplit<- split(pointsdf, (0:nrow(pointsdf))%/%25)
最后,我有以下较小数据帧的列表:
List of 3
$ 0:'data.frame': 25 obs. of 2 variables:
..$ GPSLatitude : num [1:25] 40.7 40.7 40.7 40.7 40.7 ...
..$ GPSLongitude: num [1:25] 22.9 22.9 22.9 22.9 22.9 ...
$ 1:'data.frame': 25 obs. of 2 variables:
..$ GPSLatitude : num [1:25] 40.7 40.7 40.7 40.7 40.7 ...
..$ GPSLongitude: num [1:25] 22.9 22.9 22.9 22.9 22.9 ...
$ 2:'data.frame': 8 obs. of 2 variables:
..$ GPSLatitude : num [1:8] 40.7 40.7 40.7 40.7 40.7 ...
..$ GPSLongitude: num [1:8] 22.9 22.9 22.9 22.9 22.9 ...
我尝试使用lapply来应用dist_google()函数:
lapply(length(pointssplit), dist_google(from = point2, to = pointssplit, mode = "driving", google_api = "my api key")) #point2 is my reference point
问题是我不知道如何在dist_google()中使用“ to”来管理以便分别从每个数据帧中获取经度/纬度,因此我得到了Error in match.fun(FUN)
有任何想法吗?预先谢谢你