Naming a nested list

I am trying to set names to a nested list. The following example shows the structure of a list. Here the content is "class", in my case there are tables. I would like to name the first elements of varA, and the second - var B. This will 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 to set names to this list?

+5
source share
1 answer

If I understand correctly, you can use setNames twice:

 setNames(lapply(tabs, setNames, varB), varA) #$varA1 #$varA1$varB1 #[1] "integer" # #$varA1$varB2 #[1] "integer" # ... 
+5
source

Source: https://habr.com/ru/post/1243591/


All Articles