After some manipulation, I have a list with the following elements:
$default
a b c d e
1e-05 1e-02 1e-02 0e+00 0e+00
$`1`
a d e
0.00001 35.62987 4252.45832 0.00000 0.00000
$`2`
a d e
0.00001 35.62987 4252.45832 0.00000 0.00000
The list can be reproduced with:
list1 <- list("default" = c("a" = 0.00001, "b" = 0.01, "c" = .01, "d"=0, "e"=0),
"1" = c("a" = 0.00001, 35.62987, 4252.45832, "d"=0, "e"=0),
"2" = c("a" = 0.00001, 35.62987, 4252.45832, "d"=0, "e"=0))
I'd like to quickly rename the elements of "1" and "2" to have the same names as the elements of the "standard" element i.e. "a", "b", "c", "d", "e."
But when I use lapply to reassign names, the elements of the list are lost. When I do:
lapply(list1, function(x) names(x) <- c("a", "b", "c", "d", "e"))
I get:
$default
[1] "a" "b" "c" "d" "e"
$`1`
[1] ""a" "b" "c" "d" "e"
$`2`
[1] "a" "b" "c" "d" "e"
such that all the actual values are lost. Is there a better way to do renaming across list elements?