filmov
tv
Create Nested List in R (2 Examples) | for-Loop, list, length & get Functions Explained in RStudio

Показать описание
R code of this video:
list_1 <- list(12:20, # Create first example list
letters[16:11],
"yyyy")
list_1 # Print first example list
list_2 <- list(4:8, # Create second example list
letters[7:1],
"xxx")
list_2 # Print second example list
list_3 <- list("Another", # Create third example list
"list",
"in R")
list_3 # Print third example list
my_nested_list1 <- list(list_1, # Create nested list using list()
list_2,
list_3)
my_nested_list1 # Print nested list
my_list_names <- c("list_1", "list_2", "list_3") # Create vector of list names
my_list_names # Print vector of list names
my_nested_list2 <- list() # Create empty list
my_nested_list2 # Print empty list
for(i in 1:length(my_list_names)) { # Run for-loop over lists
my_nested_list2[[i]] <- get(my_list_names[i])
}
my_nested_list2 # Print nested list
Follow me on Social Media:
list_1 <- list(12:20, # Create first example list
letters[16:11],
"yyyy")
list_1 # Print first example list
list_2 <- list(4:8, # Create second example list
letters[7:1],
"xxx")
list_2 # Print second example list
list_3 <- list("Another", # Create third example list
"list",
"in R")
list_3 # Print third example list
my_nested_list1 <- list(list_1, # Create nested list using list()
list_2,
list_3)
my_nested_list1 # Print nested list
my_list_names <- c("list_1", "list_2", "list_3") # Create vector of list names
my_list_names # Print vector of list names
my_nested_list2 <- list() # Create empty list
my_nested_list2 # Print empty list
for(i in 1:length(my_list_names)) { # Run for-loop over lists
my_nested_list2[[i]] <- get(my_list_names[i])
}
my_nested_list2 # Print nested list
Follow me on Social Media:
Комментарии