crossing / mutate is slow, how could i optimize this call?

二次信任 提交于 2020-07-20 03:42:39

问题


i have this call

distances <- crossing(nodes, gps_points) %>%
    mutate(dist = geosphere::distHaversine(cbind(lon, lat), cbind(rlon, rlat)))

But it takes a long time to complete. Just a crossing function takes 0.36 sec. Whole Statement takes 2.587 sec.

Is it possible to optimize this call?

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")

you can also download node and gps_points as csv or dput files here:

node and gps_points csv files

node and gps_points dput files

Thank you very much, BR.


回答1:


I changed geosphere::distHaversine to geodist::geodist_vec() with the setting measure = "cheap" to improve the runtime.



来源:https://stackoverflow.com/questions/62871216/crossing-mutate-is-slow-how-could-i-optimize-this-call

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!