Here we are explaining how to write an R program to extract all elements except the 3rd one of the first vectors of a list. Here we are using a built-in function list() for this. This function helps to create a list. The syntax of this function is
Below are the steps used in the R program to extract all elements except the 3rd one of the first vectors of a list. In this R program, we directly give the values to a built-in function list(). Here we are using variables L1 for holding the list elements g1,g2,g3. Call the function list() with different types of elements. Extract all elements except the 3rd one of the first vector as like L1\(g1 = L1\)g1[-3]. Finally, print the vector value.
L1 = list(g1 = 1:5, g2 = "C Programming", g3 = "JAVA")
print("Original list:")
## [1] "Original list:"
print(L1)
## $g1
## [1] 1 2 3 4 5
##
## $g2
## [1] "C Programming"
##
## $g3
## [1] "JAVA"
print("First vector:")
## [1] "First vector:"
print(L1$g1)
## [1] 1 2 3 4 5
print("First vector without third element:")
## [1] "First vector without third element:"
L1$g1 = L1$g1[-3]
print(L1$g1)
## [1] 1 2 4 5