中的名称unlist
大致符合您的要求:
> test <- list(
+ home = list(
+ jerry = c("R", "bla"),
+ mary = "xx"
+ ),
+ tmp = c("foo", "bar"),
+ etc = c()
+ )
> unlist(test)
home.jerry1 home.jerry2 home.mary tmp1 tmp2
"R" "bla" "xx" "foo" "bar"
也处理多级递归:
> test <- list(
+ home = list(
+ jerry = list(a="R", b="bla"),
+ mary = list(c="xx")
+ ),
+ tmp = list(d="foo", e="bar"),
+ etc = list(nothing=NULL)
+ )
> unlist(test)
home.jerry.a home.jerry.b home.mary.c tmp.d tmp.e
"R" "bla" "xx" "foo" "bar"
从那里很容易添加你想要的最后一点(最终值是最后一个路径元素):
> unl <- unlist(test)
> res <- names(unl)
> res <- paste(res,unl,sep=".")
> res
[1] "home.jerry.a.R" "home.jerry.b.bla" "home.mary.c.xx" "tmp.d.foo" "tmp.e.bar"