I am trying to set names to a nested list. The example below shows the structure of the list. Here the content is "class" in my case there are tables. I would like to name the first elements to varA and the second to var B. This would give something like:
[[varA1]]
[[varA1]][[varB1]]
Here is the structure of the nested list:
varA = paste0("varA", 1:10)
varB = paste0("varB", 1:3)
library(foreach)
tabs = foreach(j = 1:length(varA)) %do% {
main = varA[j]
mytabs = lapply(1:length(varB), class)
}
How can I set names to this list?
If I understand correctly, you can use setNames
twice:
setNames(lapply(tabs, setNames, varB), varA)
#$varA1
#$varA1$varB1
#[1] "integer"
#
#$varA1$varB2
#[1] "integer"
# ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With