用lapply(s)的参数命名lapply(s,fun)创建的列表(L)的元素

时间:2018-09-07 21:00:38

标签: r apply lapply naming

在此示例中:

> s <- letters[1:3]
> L <- lapply(s,rep,5)
> L
[[1]]
[1] "a" "a" "a" "a" "a"

[[2]]
[1] "b" "b" "b" "b" "b"

[[3]]
[1] "c" "c" "c" "c" "c"

如何用s的对应元素命名L的元素?

我想拥有的是:

> L
[["a"]]
[1] "a" "a" "a" "a" "a"

[["b"]]
[1] "b" "b" "b" "b" "b"

[["c"]]
[1] "c" "c" "c" "c" "c"

编辑:在我的情况下s非常大,因此没有手动解决方案。我宁愿在创建L时或之后立即命名L的元素。

0 个答案:

没有答案