Learn R Programming

qdap (version 1.3.5)

list2df: List/Matrix/Vector to Dataframe

Description

list2df - Convert a named list of vectors to a dataframe. matrix2df - Convert a matrix to a dataframe and convert the rownames to the first column. vect2df - Convert a named vector to a dataframe. list_df2df - Convert a list of equal numbered/named columns to a dataframe using the list names as the level two variable. list_vect2df - Convert a list of named vectors to a hierarchical dataframe.

Usage

list2df(list.object, col1 = "X1", col2 = "X2")

matrix2df(matrix.object, col1 = "var1")

vect2df(vector.object, col1 = "X1", col2 = "X2", order = TRUE,
  rev = FALSE)

list_df2df(list.df.object, col1 = "X1")

list_vect2df(list.vector.object, col1 = "X1", col2 = "X2", col3 = "X3",
  ...)

Arguments

list.object
A named list of vectors..
col1
Name for column 1 (the vector elements if converting a list or the rownames if converting a matrix).
col2
Name for column 2 (the names of the vectors).
matrix.object
A matrix or simple_triplet_matrix object.
vector.object
A vector object.
order
logical. If TRUE the dataframe will be ordered.
rev
logical. If TRUE and order = TRUE the dataframe will be ordered in descending order.
list.df.object
A list of dataframes with equal number/named of columns.
list.vector.object
A list of dataframes with equal number/named of columns.
col3
The name of the third column (list_vect2df).
...
Further arguments passed to vect2df)

Value

  • list2df - Returns a dataframe with two columns. matrix2df - Returns a dataframe. vect2df - Returns a dataframe. list_df2df - Returns a dataframe. list_vect2df - Returns a dataframe.

Details

generally an internal function used for reshaping data.

Examples

Run this code
lst1 <- list(x=c("foo", "bar"), y=1:5)
list2df(lst1)

lst2 <- list(a=qcv(hello, everybody), b = mtcars[1:6, 1])
list2df(lst2, "col 1", "col 2")

matrix2df(mtcars)
matrix2df(cor(mtcars))
matrix2df(matrix(1:9, ncol=3))

vect2df(1:10)
vect2df(c(table(mtcars[, "gear"])))

list_df2df(list(mtcars, mtcars))

L1 <- list(a=1:10, b=1:6, c=5:8)
list_vect2df(L1)

Run the code above in your browser using DataLab