Skip to contents

Coerce object to S4 DataFrame

Usage

as.DataFrame(x, ...)

# S4 method for GenomicRanges
as.DataFrame(x)

# S4 method for IntegerRanges
as.DataFrame(x)

# S4 method for Matrix
as.DataFrame(x)

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

# S4 method for data.frame
as.DataFrame(x)

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

# S4 method for matrix
as.DataFrame(x)

Arguments

x

Object.

row.names

Refer to base::as.data.frame for usage details.

...

Additional arguments.

Value

DataFrame.

Note

Updated 2022-05-03.

Examples

data(
    sparseMatrix,
    package = "AcidTest"
)

## `Matrix` to `DataFrame` ====
from <- sparseMatrix
to <- as.DataFrame(from)
print(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

## `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)
print(to)
#> DataFrame with 2 rows and 2 columns
#>        a      b
#>   <list> <list>
#> 1    1,2       
#> 2    3,4