Deleting Components of a List
To delete components of a R list, first of all, we need to access those components and then insert a negative sign before those components. It indicates that we had to delete that component.
Example:
R
# R program to access # components of a list # Creating a list by naming all its components empId = c (1, 2, 3, 4) empName = c ( "Debi" , "Sandeep" , "Subham" , "Shiba" ) numberOfEmp = 4 empList = list ( "ID" = empId, "Names" = empName, "Total Staff" = numberOfEmp ) cat ( "Before deletion the list is\n" ) print (empList) # Deleting a top level components cat ( "After Deleting Total staff components\n" ) print (empList[-3]) # Deleting a inner level components cat ( "After Deleting sandeep from name\n" ) print (empList[[2]][-2]) |
Output
Before deletion the list is $ID [1] 1 2 3 4 $Names [1] "Debi" "Sandeep" "Subham" "Shiba" $`Total Staff` [1] 4 After Deleting Total staff components $ID [1] 1 2 3 4 $Names [1] "Debi" "Sand...
R – Lists
A list in R programming is a generic object consisting of an ordered collection of objects. Lists are one-dimensional, heterogeneous data structures.
The list can be a list of vectors, a list of matrices, a list of characters, a list of functions, and so on.
A list is a vector but with heterogeneous data elements. A list in R is created with the use of the list() function.
R allows accessing elements of an R list with the use of the index value. In R, the indexing of a list starts with 1 instead of 0.
Contact Us