Coerce to DataFrame.

as.DataFrame(x, ...)

# S4 method for list
as.DataFrame(x, row.names = NULL)

Arguments

x

Object.

row.names

NULL or character.

...

Additional arguments.

Value

DataFrame.

Note

Don't define as coercion method for list here. It will create issues with data.frame coercion. Use as.DataFrame instead to coerce a list to DataFrame.

Updated 2020-01-18.

Examples

data(data.table, sparseMatrix, tbl_df, package = "acidtest") ## Matrix to DataFrame ==== from <- sparseMatrix to <- as(from, "DataFrame") to
#> DataFrame with 8 rows and 10 columns #> sample01 sample02 sample03 sample04 sample05 sample06 sample07 #> <numeric> <numeric> <numeric> <numeric> <numeric> <numeric> <numeric> #> gene01 0 7 0 0 0 0 0 #> gene02 0 0 0 0 0 0 0 #> gene03 0 0 0 0 0 0 0 #> gene04 0 0 0 0 0 21 0 #> gene05 0 0 0 0 0 0 28 #> gene06 0 0 0 0 0 0 0 #> gene07 0 0 0 0 0 0 0 #> gene08 0 0 0 0 0 0 0 #> sample08 sample09 sample10 #> <numeric> <numeric> <numeric> #> gene01 0 0 0 #> gene02 0 0 0 #> gene03 0 14 0 #> gene04 0 0 0 #> gene05 0 0 0 #> gene06 35 0 0 #> gene07 0 42 0 #> gene08 0 0 49
## data.table to DataFrame ==== from <- data.table to <- as(from, "DataFrame") head(to)
#> DataFrame with 4 rows and 4 columns #> sample01 sample02 sample03 sample04 #> <integer> <integer> <integer> <integer> #> gene01 1 2 3 4 #> gene02 5 6 7 8 #> gene03 9 10 11 12 #> gene04 13 14 15 16
## tbl_df to DataFrame ==== from <- tbl_df to <- as(from, "DataFrame") head(to)
#> DataFrame with 4 rows and 4 columns #> sample01 sample02 sample03 sample04 #> <integer> <integer> <integer> <integer> #> gene01 1 2 3 4 #> gene02 5 6 7 8 #> gene03 9 10 11 12 #> gene04 13 14 15 16
## list to DataFrame ==== ## Use `as.DataFrame()` instead of `as()` for `list` class. from <- list( a = list(c(1, 2), c(3, 4)), b = list(NULL, NULL) ) to <- as.DataFrame(from) to
#> DataFrame with 2 rows and 2 columns #> a b #> <list> <list> #> 1 1,2 #> 2 3,4