Merging Lists
R allows us to merge one or more lists into one list. Merging is done with the help of the list() function also. To merge the lists, we have to pass all the lists into list function as a parameter, and it returns a list which contains all the elements which are present in the lists. Let see an example to understand how the merging process is done.
Example
# Creating two lists. Even_list <- list(2,4,6,8,10) Odd_list <- list(1,3,5,7,9) # Merging the two lists. merged.list <- list(Even_list,Odd_list) # Printing the merged list. print(merged.list)
Output:
[[1]] [[1]][[1]] [1] 2 [[1]][[2]] [1] 4 [[1]][[3]] [1] 6 [[1]][[4]] [1] 8 [[1]][[5]] [1] 10 [[2]] [[2]][[1]] [1] 1 [[2]][[2]] [1] 3 [[2]][[3]] [1] 5 [[2]][[4]] [1] 7 [[2]][[5]] [1] 9