Coerce object to S4 DataFrame
Usage
as.DataFrame(x, ...)
# S4 method for GRanges
as.DataFrame(x)
# S4 method for IRanges
as.DataFrame(x)
# S4 method for Matrix
as.DataFrame(x)
# S4 method for SimpleList
as.DataFrame(x)
# S4 method for data.frame
as.DataFrame(x)
# S4 method for list
as.DataFrame(x)
# S4 method for matrix
as.DataFrame(x)
Examples
data(GRanges, sparseMatrix, package = "AcidTest")
## `GRanges` to `DFrame` ====
from <- GRanges
to <- as.DataFrame(from)
print(to)
#> DataFrame with 5 rows and 7 columns
#> seqnames start end width strand geneId
#> <Rle> <integer> <integer> <integer> <Rle> <Rle>
#> ENSG00000000003 X 100627109 100639991 12883 - ENSG00000000003
#> ENSG00000000005 X 100584802 100599885 15084 + ENSG00000000005
#> ENSG00000000419 20 50934867 50958555 23689 - ENSG00000000419
#> ENSG00000000457 1 169849631 169894267 44637 - ENSG00000000457
#> ENSG00000000460 1 169662007 169854080 192074 + ENSG00000000460
#> geneName
#> <Rle>
#> ENSG00000000003 TSPAN6
#> ENSG00000000005 TNMD
#> ENSG00000000419 DPM1
#> ENSG00000000457 SCYL3
#> ENSG00000000460 C1orf112
## `Matrix` to `DFrame` ====
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 `DFrame` ====
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