1

In this example:

> 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"

How can I name the elements of L by the corresponding element of s?

What I would like to have is:

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

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

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

Edit: in my case s is very large, so no manual solution. I would prefer to name the elements of L at the moment of creating L, or immediately after.

LucasMation
  • 2,408
  • 2
  • 22
  • 45
  • @李哲源, tks. My case is a little different, as the content of the names of the elements and the elements themselves are different (although in my example they are similar). I think this works though: `names(L) <- letters[1:3]` . Is there any problem with this solution? – LucasMation Sep 07 '18 at 21:13

0 Answers0