Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming a nested list

Tags:

list

r

nested

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?

like image 885
Henk Avatar asked Feb 22 '16 15:02

Henk


1 Answers

If I understand correctly, you can use setNames twice:

setNames(lapply(tabs, setNames, varB), varA)
#$varA1
#$varA1$varB1
#[1] "integer"
#
#$varA1$varB2
#[1] "integer"
# ...
like image 113
talat Avatar answered Oct 04 '22 13:10

talat