我无法使用c()将嵌套列表作为组件添加到列表中。请 考虑示例:
list1 <- list(1,2)
list3 <- c(list1, "list2"=list("a",4))
list3[4]
这给出:
$`list22
[1] 4`
但是没有第四部分。按照我遵循的说明手册,我们可以通过以下方式将新组件添加到列表中
new_list <- c(old_list, new_component)
我添加了新组件(list2
),它是第三个组件。append()
也给出相同的结果。
如果@Hobo Sheep的评论正确(长度为2的列表):
list1 <- list(1,2)
list3 <- list(
list1,
list(
list2 = list(
"a",
3
)
)
)
length(list3)
如果要使用 append
list3 <- append(list1, list(list2 = list("a", 3)))
str(list3)
list
R〜= JSON中的A ,因此如果您更熟悉JSON:
jsonlite::toJSON(list3, auto_unbox = TRUE, pretty = TRUE)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句