Method 2 : Using c() function
This is used to combine two lists
Syntax:
c(list1,list2)
where,
- list1 is the first list
- list2 is the second list
Example: R program to create a list1 with strings and list2 with a list of integers and merge using c() function
R
# create a list of strings list1 = list ( "sravan" , "bobby" , "ojaswi" , "satwik" , "rohith" , "gnanesh" ) # create a list of numbers list2= list (1,2,3,4,5) # merge the two lists by using c() # function list3= c (list1,list2) list3 |
Output:
[[1]] [1] "sravan" [[2]] [1] "bobby" [[3]] [1] "ojaswi" [[4]] [1] "satwik" [[5]] [1] "rohith" [[6]] [1] "gnanesh" [[7]] [1] 1 [[8]] [1] 2 [[9]] [1] 3 [[10]] [1] 4 [[11]] [1] 5
How to combine Two Lists in R
In this article , we are going to merge two lists in R programming language.