Creating a lists of lists
list1 <- list(attr = "Fruits", value = c("mango", "apple", "strawberries"))
list2 <- list(attr = "Vegetables", value = c("tomato", "potato"))
list3 <- list(attr = "Tidyverse", value = c("dplyr", "plyr", "ggplot2"))
list4 <- list(attr = "Workflow", value = c("Data Cleaning", "Modeling", "Visualization", "Communication"))
list_val <- list(list1, list2, list3, list4)
list_val
## [[1]]
## [[1]]$attr
## [1] "Fruits"
##
## [[1]]$value
## [1] "mango" "apple" "strawberries"
##
##
## [[2]]
## [[2]]$attr
## [1] "Vegetables"
##
## [[2]]$value
## [1] "tomato" "potato"
##
##
## [[3]]
## [[3]]$attr
## [1] "Tidyverse"
##
## [[3]]$value
## [1] "dplyr" "plyr" "ggplot2"
##
##
## [[4]]
## [[4]]$attr
## [1] "Workflow"
##
## [[4]]$value
## [1] "Data Cleaning" "Modeling" "Visualization" "Communication"
Parse lists of lists in a for-loop
attr_names = vector("character", length(list_val))
for (i in 1:length(list_val))
{
list_name <- list_val[[i]]$attr
assign(list_name, list_val[[i]]$value)
attr_names[[i]] <- list_name
}
# Parsed lists of lists
Fruits
## [1] "mango" "apple" "strawberries"
## [1] "dplyr" "plyr" "ggplot2"
## [1] "Data Cleaning" "Modeling" "Visualization" "Communication"