Here we are explaining how to write an R program to assign NULL to a given list element. Here we are using a NULL object for the assignment. it is a reserved word and it is often returned by the expressions or functions whose value is undefined. The syntax of NULL using conditions
– where x is an object to be tested, and dots(…) are to be ignored.
Below are the steps used in the R program to assign NULL value to a given list element. In this R program, we directly give the value NULL to the element. First, assign a list to the variable lis. And assign value NULL by specifying the position of value in the list.
lis = list(10, 20, 30, 40, 50)
print("Original list is:")
## [1] "Original list is:"
print(lis)
## [[1]]
## [1] 10
##
## [[2]]
## [1] 20
##
## [[3]]
## [1] 30
##
## [[4]]
## [1] 40
##
## [[5]]
## [1] 50
print("Set 2nd and 3rd elements changes to NULL")
## [1] "Set 2nd and 3rd elements changes to NULL"
lis[2] = list(NULL)
lis[3] = list(NULL)
print(lis)
## [[1]]
## [1] 10
##
## [[2]]
## NULL
##
## [[3]]
## NULL
##
## [[4]]
## [1] 40
##
## [[5]]
## [1] 50
lis = list(10, 20, 30, 40, 50, 60, 70, 80, 90)
print("Original list is:")
## [1] "Original list is:"
print(lis)
## [[1]]
## [1] 10
##
## [[2]]
## [1] 20
##
## [[3]]
## [1] 30
##
## [[4]]
## [1] 40
##
## [[5]]
## [1] 50
##
## [[6]]
## [1] 60
##
## [[7]]
## [1] 70
##
## [[8]]
## [1] 80
##
## [[9]]
## [1] 90
print("Set 2nd and 3rd elements changes to NULL")
## [1] "Set 2nd and 3rd elements changes to NULL"
lis[3] = list(NULL)
lis[5] = list(NULL)
lis[7] = list(NULL)
print(lis)
## [[1]]
## [1] 10
##
## [[2]]
## [1] 20
##
## [[3]]
## NULL
##
## [[4]]
## [1] 40
##
## [[5]]
## NULL
##
## [[6]]
## [1] 60
##
## [[7]]
## NULL
##
## [[8]]
## [1] 80
##
## [[9]]
## [1] 90