Convert List of Vectors to DataFrame in R
Last Updated :
09 May, 2021
In this article, we will discuss how to convert the given list of vectors to Dataframe using the help of different functions in the R Programming Language.
For all the methods discussed below, few functions are common because of their functionality. Let us discuss them first.
- as.data.frame() is one of the simplest methods to convert the given list of vectors to the DataFrame in R language with just calling the as.data.frame() function and passing the required parameters, and further this function will be returning the DataFrame converted from the list of vectors given before.
Syntax: as.data.frame(x, row.names = NULL, optional = FALSE, …)
- Further, with the as.data.frame() function user needs to also call the do.call() function which is used here to constructs and executes a function call from a name or a function and a list of arguments to be passed to it.
Syntax: do.call(what, args, quote = FALSE, envir = parent.frame())
Parameters:
- what:-either a function or a non-empty character string naming the function to be called.
- args:a list of arguments to the function call. The names attribute of args gives the argument names.
- quote:-a logical value indicating whether to quote the arguments.
- envir:-an environment within which to evaluate the call.
Method 1: Using cbind()
cbind() function stands for column-bind. This function can be used to combine several vectors, matrices, or DataFrames by columns.
Syntax: cbind(x1, x2, …, deparse.level = 1)
In this approach, a single vector is considered as one column and then these columns are combined to form a dataframe.
Example:
R
my_list <- list(A =c(1,2,3,4,5),
B =c(6,7,8,9,10))
my_list
as.data.frame(do.call(cbind, my_list))
Output:

Method 2: Using rbind()
rbind() function stands for row-bind. This function can be used to combine several vectors, matrices, or DataFrames by rows.
Syntax: rbind(x1, x2, …, deparse.level = 1)
Parameters:
x1, x2: vector, matrix, DataFrames
deparse.level: This value determines how the column names generated. The default value of deparse.level is 1.
In this approach, each vector is considered a row and then these rows are combined to form a dataframe.
Example:
R
my_list <- list(A =c(1,2,3,4,5),
B =c(6,7,8,9,10))
my_list
as.data.frame(do.call(rbind, my_list))
Output:
Similar Reads
Convert dataframe to list of vectors in R In this article, we will learn how to convert a dataframe into a list of vectors, such that we can use columns of the dataframes as vectors in the R Programming language. Dataframe columns as a list of vectors as.list() function in R Language is used to convert an object to a list. These objects can
3 min read
Convert Named Vector to DataFrame in R In this article, we will see how to convert the named vector to Dataframe in the R Programming Language. Method 1: Generally while converting a named vector to a dataframe we may face a problem. That is, names of vectors may get converted into row names, and data may be converted into a single colu
1 min read
Convert list of lists to dataframe in R In this article, we will discuss how to convert a list of lists to dataframe in R Programming Language. We will convert a list of lists to a data frame both by row and by column. Example 1: R program to create three lists inside a list with numeric and character type and convert into dataframe by co
2 min read
Convert large list to dataframe in R In this article, we will discuss how to convert a large list to a dataframe in the R Programming Language. Method 1 : Using rbindlist() First, create a large list. Then use the Map function on the list and convert it to dataframe using the as.data.frame function in R. The map function applies a fun
3 min read
Convert Nested Lists to Dataframe in R In this article, we will discuss how to Convert Nested Lists to Dataframe in R Programming Language. It can be done with two methods: Convert Nested lists to Data Frame by Column.Convert Nested lists to Data Frame by Row. First, let's Create a nested list. Code block Output: fig 1: Nested List Metho
3 min read
Convert dataframe column to list in R In this article, we will learn how to convert a dataframe into a list by columns in R Programming language. We will be using as.list() function, this function is used to convert an object to a list. These objects can be Vectors, Matrices, Factors, and data frames. Syntax: as.list( object ) Parameter
2 min read