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.
我有两个具有完全相同数量的元素的列表。我想将名称从一个列表复制到另一个列表。
将unlist/relist用于嵌套列表:
unlist
relist
a <- list(x=1, y=2, z=list(foo=1:5)) b <- list(p="a", q="b", r=list(bar=1:5)) copyNames <- function(l1, l2) { relist(unlist(l1), l2) } copyNames(a,b)
这假设您在列表中确实具有完全相同数量的元素以及列表中的所有向量等。