在此示例中,我有以下列表nodes_found与 2 个元素,但元素的数量在未来会有所不同:
library(osmar)
>nodes_found
$`1`
osmar object
0 nodes, 0 ways, 0 relations
$`2`
osmar object
1 nodes, 0 ways, 0 relations
> class(nodes_found)
[1] "list"
我想从列表中删除空的 osmar 对象(在本例中为 0 个节点的对象是 [1] 处的对象)。也许根据节点的属性进行过滤?如果我基本上请求包含 0 个节点的 osmar 对象的属性,它将生成一个具有 0 行的数据结构。所以也许我可以使用它。但我不认为它有效。
这是 nodes_found 列表:
nodes_found<-list(`1` = structure(list(nodes = structure(list(attrs = structure(list(
id = numeric(0), visible = character(0), timestamp = structure(list(
sec = numeric(0), min = integer(0), hour = integer(0),
mday = integer(0), mon = integer(0), year = integer(0),
wday = integer(0), yday = integer(0), isdst = integer(0),
zone = character(0), gmtoff = integer(0)), class = c("POSIXlt",
"POSIXt")), version = numeric(0), changeset = numeric(0),
user = structure(integer(0), .Label = character(0), class = "factor"),
uid = structure(integer(0), .Label = character(0), class = "factor"),
lat = numeric(0), lon = numeric(0)), row.names = integer(0), class = "data.frame"),
tags = structure(list(id = numeric(0), k = structure(integer(0), .Label = character(0), class = "factor"),
v = structure(integer(0), .Label = character(0), class = "factor")), row.names = integer(0), class = "data.frame")), class = c("nodes",
"osmar_element", "list")), ways = structure(list(attrs = structure(list(
id = numeric(0), visible = character(0), timestamp = structure(list(
sec = numeric(0), min = integer(0), hour = integer(0),
mday = integer(0), mon = integer(0), year = integer(0),
wday = integer(0), yday = integer(0), isdst = integer(0),
zone = character(0), gmtoff = integer(0)), class = c("POSIXlt",
"POSIXt")), version = numeric(0), changeset = numeric(0),
user = structure(integer(0), .Label = character(0), class = "factor"),
uid = structure(integer(0), .Label = character(0), class = "factor")), row.names = integer(0), class = "data.frame"),
tags = structure(list(id = numeric(0), k = structure(integer(0), .Label = character(0), class = "factor"),
v = structure(integer(0), .Label = character(0), class = "factor")), row.names = integer(0), class = "data.frame"),
refs = structure(list(id = numeric(0), ref = numeric(0)), row.names = integer(0), class = "data.frame")), class = c("ways",
"osmar_element", "list")), relations = structure(list(attrs = structure(list(
id = numeric(0), visible = character(0), timestamp = structure(list(
sec = numeric(0), min = integer(0), hour = integer(0),
mday = integer(0), mon = integer(0), year = integer(0),
wday = integer(0), yday = integer(0), isdst = integer(0),
zone = character(0), gmtoff = integer(0)), class = c("POSIXlt",
"POSIXt")), version = numeric(0), changeset = numeric(0),
user = structure(integer(0), .Label = character(0), class = "factor"),
uid = structure(integer(0), .Label = character(0), class = "factor")), row.names = integer(0), class = "data.frame"),
tags = structure(list(id = numeric(0), k = structure(integer(0), .Label = character(0), class = "factor"),
v = structure(integer(0), .Label = character(0), class = "factor")), row.names = integer(0), class = "data.frame"),
refs = structure(list(id = numeric(0), type = structure(integer(0), .Label = character(0), class = "factor"),
ref = numeric(0), role = structure(integer(0), .Label = character(0), class = "factor")), row.names = integer(0), class = "data.frame")), class = c("relations",
"osmar_element", "list"))), class = c("osmar", "list")), `2` = structure(list(
nodes = structure(list(attrs = structure(list(id = 7018492265,
visible = NA_character_, timestamp = structure(list(sec = 42,
min = 7L, hour = 17L, mday = 5L, mon = 2L, year = 121L,
wday = 5L, yday = 63L, isdst = 0L, zone = "UTC",
gmtoff = NA_integer_), class = c("POSIXlt", "POSIXt"
)), version = 1, changeset = NA_real_, user = structure(NA_integer_, .Label = character(0), class = "factor"),
uid = structure(NA_integer_, .Label = character(0), class = "factor"),
lat = 48.1102703, lon = 11.8303853), row.names = 4281593L, class = "data.frame"),
tags = structure(list(id = numeric(0), k = structure(integer(0), .Label = character(0), class = "factor"),
v = structure(integer(0), .Label = character(0), class = "factor")), row.names = integer(0), class = "data.frame")), class = c("nodes",
"osmar_element", "list")), ways = structure(list(attrs = structure(list(
id = numeric(0), visible = character(0), timestamp = structure(list(
sec = numeric(0), min = integer(0), hour = integer(0),
mday = integer(0), mon = integer(0), year = integer(0),
wday = integer(0), yday = integer(0), isdst = integer(0),
zone = character(0), gmtoff = integer(0)), class = c("POSIXlt",
"POSIXt")), version = numeric(0), changeset = numeric(0),
user = structure(integer(0), .Label = character(0), class = "factor"),
uid = structure(integer(0), .Label = character(0), class = "factor")), row.names = integer(0), class = "data.frame"),
tags = structure(list(id = numeric(0), k = structure(integer(0), .Label = character(0), class = "factor"),
v = structure(integer(0), .Label = character(0), class = "factor")), row.names = integer(0), class = "data.frame"),
refs = structure(list(id = numeric(0), ref = numeric(0)), row.names = integer(0), class = "data.frame")), class = c("ways",
"osmar_element", "list")), relations = structure(list(attrs = structure(list(
id = numeric(0), visible = character(0), timestamp = structure(list(
sec = numeric(0), min = integer(0), hour = integer(0),
mday = integer(0), mon = integer(0), year = integer(0),
wday = integer(0), yday = integer(0), isdst = integer(0),
zone = character(0), gmtoff = integer(0)), class = c("POSIXlt",
"POSIXt")), version = numeric(0), changeset = numeric(0),
user = structure(integer(0), .Label = character(0), class = "factor"),
uid = structure(integer(0), .Label = character(0), class = "factor")), row.names = integer(0), class = "data.frame"),
tags = structure(list(id = numeric(0), k = structure(integer(0), .Label = character(0), class = "factor"),
v = structure(integer(0), .Label = character(0), class = "factor")), row.names = integer(0), class = "data.frame"),
refs = structure(list(id = numeric(0), type = structure(integer(0), .Label = character(0), class = "factor"),
ref = numeric(0), role = structure(integer(0), .Label = character(0), class = "factor")), row.names = integer(0), class = "data.frame")), class = c("relations",
"osmar_element", "list"))), class = c("osmar", "list")))