In [2]:
L=list(10,3.45,"Itronix",56,3.45,"Solutions")
L
- 10
- 3.45
- ‘Itronix’
- 56
- 3.45
- ‘Solutions’
In [4]:
L[1]
L[2]
- 10
- 3.45
In [25]:
# Add element at the end of the list.
L[4] = "Karan Arora"
print(L[4])
# Remove the last element.
L[4] = NULL
# Print the 4th Element.
print(L[4])
# Update the 3rd Element.
L[3] = "iTronix"
print(L[3])
[[1]] [1] "Karan Arora" [[1]] [1] 3.45 [[1]] [1] "iTronix"
In [26]:
print(L)
[[1]] [1] 10 [[2]] [1] 3.45 [[3]] [1] "iTronix" [[4]] [1] 3.45 [[5]] [1] "Solutions"
In [5]:
L1=list(1,2,3)
L2=list(4,5,6)
Merge=c(L1,L2)
Merge
- 1
- 2
- 3
- 4
- 5
- 6
Converting List to Vector
A list can be converted to a vector so that the elements of the vector can be used for further manipulation. All the arithmetic operations on vectors can be applied after the list is converted into vectors. To do this conversion, we use the unlist() function. It takes the list as input and produces a vector.
In [9]:
list1 = list(1:5)
list1
list2 =list(10:14)
list2
# Convert the lists to vectors.
v1 = unlist(list1)
v2 = unlist(list2)
v1
v2
# Now add the vectors
result = v1+v2
result
- 1
- 2
- 3
- 4
- 5
- 10
- 11
- 12
- 13
- 14
- 1
- 2
- 3
- 4
- 5
- 10
- 11
- 12
- 13
- 14
- 11
- 13
- 15
- 17
- 19
In [ ]:
In [ ]: