穿越/变异很慢,我该如何优化这个调用? [英] crossing / mutate is slow, how could i optimize this call?
本文介绍了穿越/变异很慢,我该如何优化这个调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个电话
distances <- crossing(nodes, gps_points) %>%
mutate(dist = geosphere::distHaversine(cbind(lon, lat), cbind(rlon, rlat)))
但是需要很长时间才能完成.只是一个交叉函数需要 0.36 秒.整个语句需要 2.587 秒.
But it takes a long time to complete. Just a crossing function takes 0.36 sec. Whole Statement takes 2.587 sec.
是否可以优化此调用?
dput(head(nodes))
structure(list(ids = c(292376151, 1112377287, 6902561109, 5324247975,
1112377281, 7018492265), ids_igraph = c(128974, 128973, 128972,
128971, 128970, 128969), lon = c(11.831088, 11.830884, 11.8307377,
11.8307106, 11.8305447, 11.8303853), lat = c(48.1111416, 48.1108747,
48.1106855, 48.1106505, 48.1104559, 48.1102703)), row.names = c(833886L,
2173435L, 4292366L, 4058008L, 2173434L, 4315822L), class = "data.frame")
dput(head(gps_points))
structure(list(rlon = c(11.7989692, 11.7982155, 11.7968209, 11.7961655,
11.7957267, 11.7944537), rlat = c(48.0742471, 48.0739067, 48.0733855,
48.0730923, 48.0728656, 48.0722014)), row.names = c(3250429L,
3250548L, 323901L, 3250542L, 3250544L, 323902L), class = "data.frame")
您还可以在此处下载 node
和 gps_points
作为 csv 或 dput 文件:
you can also download node
and gps_points
as csv or dput files here:
非常感谢,BR.
推荐答案
我将 geosphere::distHaversine
更改为 geodist::geodist_vec()
并设置 measure = "cheap"
以改善运行时间.
I changed geosphere::distHaversine
to geodist::geodist_vec()
with the setting measure = "cheap"
to improve the runtime.
这篇关于穿越/变异很慢,我该如何优化这个调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文