How to create a list in R
Last Updated :
23 Jul, 2025
In this article, we will discuss What is a list and various methods to create a list using R Programming Language.
What is a list?
A list is the one-dimensional heterogeneous data i.e., which stores the data of various types such as integers, float, strings, logical values, and characters. These lists provide flexibility and can be accessed by using indexing. Some of the methods to create the list are:
Creating a list by using the 'list()' function
This method is used to create the list by using the function 'list()' efficiently. In the below example, we created the list by using the function 'list()'.
R
# creating list
list1 = list("apple", "A", 550, FALSE, 5.1, c(1, 2, 3,4,5))
print("The list is")
print(list1)
Output:
[1] "The list is"
[[1]]
[1] "apple"
[[2]]
[1] "A"
[[3]]
[1] 550
[[4]]
[1] FALSE
[[5]]
[1] 5.1
[[6]]
[1] 1 2 3 4 5
In the below example, we created the list by using the function 'list()'.
R
# creating list
list= list("gfg", 550 , TRUE, 15.5, "G")
print("The list is")
print(list)
Output:
[1] "The list is"
[[1]]
[1] "gfg"
[[2]]
[1] 550
[[3]]
[1] TRUE
[[4]]
[1] 15.5
[[5]]
[1] "G"
Creating list by using Concatenation
This method is used to create the list by using the function 'c()' efficiently. In the below example, we created the the vectors and by using it, we created the list by using the function 'c()'.
R
vec1 = c("gfg", "a", "h")
vec2 = c("ramu", "b", "rakesh")
vec3 = c("lokesh", "suresh")
#creating list
list = c(vec1, vec2, vec3)
print("The list is")
print(list)
Output:
[1] "The list is"
[1] "gfg" "a" "h" "ramu" "b" "rakesh" "lokesh" "suresh"
In the below example, we created the the vectors and by using it, we created the list by using the function 'c()'.
R
a = c(43, 5.6, 23, 76)
b = c(550, 750.5, 25, 1.5)
#creating list
list1 = c(a,b)
print("The list is")
print(list1)
Output:
[1] "The list is"
[1] 43.0 5.6 23.0 76.0 550.0 750.5 25.0 1.5
Conclusion
In conclusion, we learned about how to create a list by using R. R language offers versatile tools while creating the list efficiently.
Similar Reads
How to create a matrix in R In this article, we will discuss What is a matrix and various methods to create a matrix by using R Programming Language. What is a matrix?A matrix is a two-dimensional data set that collects rows and columns. The matrix stores the data in rows and columns format. It is possible to access the data i
3 min read
How to create an array in R The array is the fundamental data structure in R used to store multiple elements of the same data type. In this article, we will explore two different approaches to creating an array in R Programming Language. Creating an array in RBelow are the approaches for creating an array in R. Using array() f
4 min read
How to Create Tables in R? In this article, we will discuss how to create tables in R Programming Language. Method 1: Create a table from scratch We can create a table by using as.table() function, first we create a table using matrix and then assign it to this method to get the table format. Syntax: as.table(data) Example: I
2 min read
How to Handle list Error in R R, a powerful and widely used programming language for statistical computing and data analysis, relies heavily on lists to store and manipulate data. However, working with lists in the R Programming Language may lead to errors if not handled properly. Table of Content Table of ContentsWhat is List ?
4 min read
How to Convert a List to a Dataframe in R We have a list of values and if we want to Convert a List to a Dataframe within it, we can use a as.data.frame. it Convert a List to a Dataframe for each value. A DataFrame is a two-dimensional tabular data structure that can store different types of data. Various functions and packages, such as dat
4 min read
Convert list to array in R A list can be converted to array in R by calling unlist( ) function with created list as parameter. Now pass the unlist() function into array() function as parameter, and use dim attribute for specifying number of rows, columns and matrices. unlist() converts list to vector. Â Syntax :Â array( unlist
1 min read