You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用tidyr的hoist()函数一次性提取嵌套列表中的经纬度

用tidyr::hoist()单次提取嵌套列表中多组经纬度的方法

我在研究嵌套列表的深层数据提取时,使用tidyr包的hoist()函数遇到了问题:目前需要分两次操作才能提取5个城市共7个地址的lat(纬度)和lng(经度)。我已经能通过unnest_wider()、unnest_longer()结合hoist()实现目标,但希望仅用hoist()单次完成提取。

示例数据如下:

library(tidyr)
library(dplyr)
library(repurrrsive)

gmaps_cities_o <- repurrrsive::gmaps_cities
gmaps_cities_o

现有分步提取操作

  • 提取第一个地址的经纬度:
gmaps_cities_o %>% 
    hoist(json, 
           lat = list("results", 1, "geometry", "location", "lat"),
           lng = list("results", 1, "geometry", "location", "lng")
           )
  • 提取第二个地址的经纬度:
gmaps_cities_o %>% 
    hoist(json, 
           lat = list("results", 2, "geometry", "location", "lat"),
           lng = list("results", 2, "geometry", "location", "lng")
           )

期望的单次提取形式

我希望能用类似以下的hoist()单次操作完成所有地址的经纬度提取,恳请有经验者提供提示:

gmaps_cities_o %>% 
    hoist(json, 
           lat = list("results", (?), "geometry", "location", "lat"),
           lng = list("results", (?), "geometry", "location", "lng")
           )

内容的提问来源于stack exchange,提问作者f0nzie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 13:53:22