Adding Item to List

To add an item to the end of list, we can use append() function.

R




# creating a list
my_numbers = c(1,5,6,3)
#adding number at the end of list
append(my_numbers, 45)
#printing list
my_numbers


Output

[1]  1  5  6  3 45
[1] 1 5 6 3


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.

Similar Reads

Creating a List

To create a List in R you need to use the function called “list()“....

Naming List Components

...

Accessing R List Components

Naming list components make it easier to access them....

Modifying Components of a List

...

Concatenation of lists

We can access components of an R list in two ways....

Adding Item to List

...

Deleting Components of a List

...

Merging list

A R list can also be modified by accessing the components and replacing them with the ones which you want....

Converting List to Vector

...

R List to matrix

Two R lists can be concatenated using the concatenation function. So, when we want to concatenate two lists we have to use the concatenation operator....

Contact Us