r语言 - 过滤列中非空的列表



我有一个专栏叫"geo"我存储了许多坐标列表,每个列表代表一个边界框。问题是我想删除geo列中的其他元素

我怎么能保持行坐标列表是可用的?我如何将这些坐标存储在一个单独的列中?见表

编辑:这是dput()

structure(list(full_name = c("Karlsruhe, Deutschland", "Karlsruhe, Deutschland", 
"Karlsruhe, Deutschland", "Volksparkstadion", "Volksparkstadion", 
"Volksparkstadion"), country_code = c("DE", "DE", "DE", "DE", 
"DE", "DE"), place_type = c("city", "city", "city", "poi", "poi", 
"poi"), name = c("Karlsruhe", "Karlsruhe", "Karlsruhe", "Volksparkstadion", 
"Volksparkstadion", "Volksparkstadion"), country = c("Deutschland", 
"Deutschland", "Deutschland", "Deutschland", "Deutschland", "Deutschland"
), id = c("5b146bf0b819f1af", "5b146bf0b819f1af", "5b146bf0b819f1af", 
"0fc3a3fa5494c000", "0fc3a3fa5494c000", "0fc3a3fa5494c000"), 
geo = list(type = "Feature", bbox = list(8.2773, 48.9405, 
8.5418, 49.0914), properties = structure(list(), .Names = character(0)), 
type = "Feature", bbox = list(9.8986, 53.5871, 9.8986, 
53.5871), properties = structure(list(), .Names = character(0)))), row.names = c(NA, 
6L), class = "data.frame")


根据结构,可能

subset(df1, lengths(geo) > 0 & names(geo) != "type")

与产出

full_name country_code place_type             name     country               id                              geo
2 Karlsruhe, Deutschland           DE       city        Karlsruhe Deutschland 5b146bf0b819f1af 8.2773, 48.9405, 8.5418, 49.0914
5       Volksparkstadion           DE        poi Volksparkstadion Deutschland 0fc3a3fa5494c000 9.8986, 53.5871, 9.8986, 53.5871

最新更新