从列表名称中创建嵌套列表(Create a nested list out of list names)

编程入门 行业动态 更新时间:2024-10-27 17:24:21
列表名称中创建嵌套列表(Create a nested list out of list names) list1 <- 1:3 list2 <- letters[1:3]

我想将它们组合在一个列表中,但不是简单地将它们列在list(list1, list2) ,而是以更通用的方式。

例如,通过使用ls(pattern = "^list*") 。 但是,这只是组合名称而不是实际列表。 您如何访问,替换或引用实际列表?

list1 <- 1:3 list2 <- letters[1:3]

I'd like to combine them in a list but not by simple listing them in list(list1, list2), but in a more generalized fashion.

For example, by using ls(pattern = "^list*"). However, that only combines the names and not the actual lists. How do you access, substitute, or refer to the actual lists?

最满意答案

听起来你正在寻找mget :

list1 <- 1:3 list2 <- letters[1:3] mget(ls(pattern = "list\\d")) # $list1 # [1] 1 2 3 # # $list2 # [1] "a" "b" "c"

It sounds like you're looking for mget:

list1 <- 1:3 list2 <- letters[1:3] mget(ls(pattern = "list\\d")) # $list1 # [1] 1 2 3 # # $list2 # [1] "a" "b" "c"

更多推荐

本文发布于:2023-08-03 08:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1385220.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:列表   嵌套   名称   Create   list

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!