R:将大型列表转换为数据框架并保持零值

发布于 2025-02-04 16:12:49 字数 2434 浏览 3 评论 0原文

我有一个称为“数据”的对象,其中包含有关房地产属性的信息:

> class(data)
[1] "data.frame"`
> dim(data)
[1] 351  13

whitin列,有一个称为“地址”的对象,

> class(data$addresses)
[1] "character"

我使用了函数cartociudad_geocode()来获取地址的最大地址:哪个地址:

geo_info<-sapply(data$addresses, cartociudad_geocode, on.error="warn")

哪个地址 :导致了351个元素的大量列表,并提供了所有被搜索的条件的地理信息。那些没有出现为 null 的人:

> dput(head(geo_info, 4))
list(`Valencia, Avenida Nº S.n. Planta 1 Castellon De La Plana/Castello De La Plana` = structure(list(
    id = "2061380170886", province = "Badajoz", comunidadAutonoma = "Extremadura", 
    muni = "Valdetorres", type = "portal", address = "PLAN PARCIAL Nº 1", 
    postalCode = "06474", poblacion = "Valdetorres", geom = "POINT(-6.07339711488708 38.91670317033)", 
    tip_via = "BARRIO", lat = 38.91670317033, lng = -6.07339711488708, 
    portalNumber = "0", stateMsg = "Resultado exacto de la búsqueda", 
    extension = "", state = "1", countryCode = "011"), row.names = c(NA, 
-1L), class = "data.frame"), `Mayor Nº S.n. Planta 1 Castellon De La Plana/Castello De La Plana` = structure(list(
    id = "2061380170886", province = "Badajoz", comunidadAutonoma = "Extremadura", 
    muni = "Valdetorres", type = "portal", address = "PLAN PARCIAL Nº 1", 
    postalCode = "06474", poblacion = "Valdetorres", geom = "POINT(-6.07339711488708 38.91670317033)", 
    tip_via = "BARRIO", lat = 38.91670317033, lng = -6.07339711488708, 
    portalNumber = "0", stateMsg = "Resultado exacto de la búsqueda", 
    extension = "", state = "1", countryCode = "011"), row.names = c(NA, 
-1L), class = "data.frame"), `Notario Mas, Plaza Nº 3 Piso 1º Castellon De La Plana` = structure(list(
    id = "120400001216", province = "Castellón/Castelló", comunidadAutonoma = "Comunitat Valenciana", 
    muni = "Castelló de la Plana", type = "portal", address = "NOTARIO MAS", 
    geom = "POINT(-0.0414310339999702 39.9877939630001)", tip_via = "PLAZA", 
    lat = 39.9877939630001, lng = -0.0414310339999702, portalNumber = "5", 
    stateMsg = "Resultado exacto de la búsqueda", state = "1", 
    countryCode = "011"), row.names = c(NA, -1L), class = "data.frame"), 
    `Mayor Nº 56 Piso 1º Castellon De La Plana` = NULL)`

我的目标是:将 geo_info 转换为数据框架,同时保持 null 行。

I have an object called 'data' containing information about real estate property:

> class(data)
[1] "data.frame"`
> dim(data)
[1] 351  13

Whitin its columns, there is one called 'addresses'

> class(data$addresses)
[1] "character"

I used the function cartociudad_geocode() to get the maximum amount of addresses geolocalized:

geo_info<-sapply(data$addresses, cartociudad_geocode, on.error="warn")

Which resulted in a large list of 351 elements, with geographical info of all of the strings of addressed that DID get geolocalized. The ones that DIDN'T appear as NULL:

> dput(head(geo_info, 4))
list(`Valencia, Avenida Nº S.n. Planta 1 Castellon De La Plana/Castello De La Plana` = structure(list(
    id = "2061380170886", province = "Badajoz", comunidadAutonoma = "Extremadura", 
    muni = "Valdetorres", type = "portal", address = "PLAN PARCIAL Nº 1", 
    postalCode = "06474", poblacion = "Valdetorres", geom = "POINT(-6.07339711488708 38.91670317033)", 
    tip_via = "BARRIO", lat = 38.91670317033, lng = -6.07339711488708, 
    portalNumber = "0", stateMsg = "Resultado exacto de la búsqueda", 
    extension = "", state = "1", countryCode = "011"), row.names = c(NA, 
-1L), class = "data.frame"), `Mayor Nº S.n. Planta 1 Castellon De La Plana/Castello De La Plana` = structure(list(
    id = "2061380170886", province = "Badajoz", comunidadAutonoma = "Extremadura", 
    muni = "Valdetorres", type = "portal", address = "PLAN PARCIAL Nº 1", 
    postalCode = "06474", poblacion = "Valdetorres", geom = "POINT(-6.07339711488708 38.91670317033)", 
    tip_via = "BARRIO", lat = 38.91670317033, lng = -6.07339711488708, 
    portalNumber = "0", stateMsg = "Resultado exacto de la búsqueda", 
    extension = "", state = "1", countryCode = "011"), row.names = c(NA, 
-1L), class = "data.frame"), `Notario Mas, Plaza Nº 3 Piso 1º Castellon De La Plana` = structure(list(
    id = "120400001216", province = "Castellón/Castelló", comunidadAutonoma = "Comunitat Valenciana", 
    muni = "Castelló de la Plana", type = "portal", address = "NOTARIO MAS", 
    geom = "POINT(-0.0414310339999702 39.9877939630001)", tip_via = "PLAZA", 
    lat = 39.9877939630001, lng = -0.0414310339999702, portalNumber = "5", 
    stateMsg = "Resultado exacto de la búsqueda", state = "1", 
    countryCode = "011"), row.names = c(NA, -1L), class = "data.frame"), 
    `Mayor Nº 56 Piso 1º Castellon De La Plana` = NULL)`

My objective is: transforming geo_info into a data frame while KEEPING the NULL rows.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文