I'm starting my journy with r, I find it incredibly fun and useful, yet I have so many things to learn so I'd appreciate any suggestions:
I have a large list of 351 elements (called 'geo_info'), which is the result of applying cartociudad_geocode()
function (which retrieves available geographic info from character strings containing addresses) to my 'addresses' vector.
Here's part of 'geo_info' str()
(bc it's too long):
$ Jesus Martin Nº 32 Planta 3 Castellon De La Plana/Castello De La Plana : NULL
$ Obispo Climent Nº S/N Planta Pb+2 Castellon De La Plana/Castello De La Plana :'data.frame': 1 obs. of 13 variables:
..$ id : chr "120400000973"
..$ province : chr "Castellón/Castelló"
..$ comunidadAutonoma: chr "Comunitat Valenciana"
..$ muni : chr "Castelló de la Plana"
..$ type : chr "portal"
..$ address : chr "OBISPO CLIMENT"
..$ geom : chr "POINT(-0.0364751229999456 39.985197242)"
..$ tip_via : chr "CALLE"
..$ lat : num 40
..$ lng : num -0.0365
..$ stateMsg : chr "Resultado exacto de la búsqueda"
..$ state : chr "1"
..$ countryCode : chr "011"
$ Huerto Sogueros, Plaza Nº Sn Planta 3 Castellon De La Plana/Castello De La Plana :'data.frame': 1 obs. of 14 variables:
..$ id : chr "120400005053"
..$ province : chr "Castellón/Castelló"
..$ comunidadAutonoma: chr "Comunitat Valenciana"
..$ muni : chr "Castelló de la Plana"
..$ type : chr "portal"
..$ address : chr "HUERTO SOGUEROS"
..$ geom : chr "POINT(-0.0421460729999694 39.986166069)"
..$ tip_via : chr "PLAZA"
..$ lat : num 40
..$ lng : num -0.0421
..$ portalNumber : chr "5"
..$ stateMsg : chr "Resultado exacto de la búsqueda"
..$ state : chr "1"
..$ countryCode : chr "011"
$ Mijares, Ronda Nº S/N Castellon De La Plana/Castello De La Plana : NULL
I want to transform such list into a data frame, and it worked when using DF<-dplyr::bind_rows(geo_info, .id = 'data.frame')
but that code doesn't take the null values into account. You can see some of the strings didn't get geolocalized (due to whatever) and appear as 'NULL'. Is there a way I can transform my list into a data frame while keeping the null elements? whith 'NA' or '0'.
For extra info, here's the code I used for the geolocalization:
geo_info<-sapply(addresses, cartociudad_geocode, on.error="warn")
And here's the head()
of the list
> 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)