Create a list containing a
vector, a list and a matrix.
list_data <- list(c("Feb","Mar","Apr"))
list("white",13.4)), matrix(c(3,9,5,1,-2,8), nrow = 2)
For Example: Give names to the elements in the list:
Names(list_data) <- c(“1 st Quarter”, “A Matrix”, “A Inner list”)
Access the first element of the list:
print(list_data[1])
Access the third element. As it also a list, all its elements will print:
Print(list_data[3])
By using the name of the element access the list elements:
Print(list_data$A Matrix)
It will produced the following result after executing the above code:
$”1 st Quarter” [1] “Feb”, "Mar”, "Apr”
$A_Inner_list
$A_Inner_list[[1]]
[1] “White”
$A_Inner_list[[2]]
[1] 13.4
$ “A Matrix” [1]
[1] [2] [3]
[1] 3 5 -2
[2] 9 1 8