Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想创建一个名称可能重复的对象列表。例如:
l <- list("a"=1:4, "a"=2:3, "b"=1)
现在我想获取名称为“a”的 l 元素(在本例中为 l[1] 和 l[2])。有什么简洁的方法可以代替遍历名称(l)吗?谢谢。
您可以为此使用基本子集:
> l[names(l) == "a"] $a [1] 1 2 3 4 $a [1] 2 3
(顺便说一句,l它是一个时髦的角色,可以单独与脚本一起使用,因为它很容易被误解为1)。
l
1