Flatten lists
Usage
unlist2(x, ...)
# S4 method for DFrameList
unlist2(x, nameCol = "name", rownameCol = "rowname")
Arguments
- x
Object.
- nameCol
character(1)
. Column name to assignnames
of input object.- rownameCol
character(1)
. Column name to assignrownames
of input object.- ...
Additional arguments.
Details
Intended primarily for complex S4 classes, such as DFrameList
.
Intentionally does not support recursion.
Examples
## DFrameList ====
suppressPackageStartupMessages({
library(IRanges)
})
dfl <- DataFrameList(
"A" = DataFrame(
"a" = c(1L, 2L),
"b" = c(3L, 4L),
row.names = c("aa", "bb")
),
"B" = DataFrame(
"a" = 5L,
"b" = 6L,
row.names = "cc"
)
)
## Our variant, which assigns into columns.
x <- unlist2(dfl)
print(x)
#> DataFrame with 3 rows and 4 columns
#> name rowname a b
#> <character> <character> <integer> <integer>
#> 1 A aa 1 3
#> 2 A bb 2 4
#> 3 B cc 5 6
## Compare with the standard variant, which modifies rownames.
y <- unlist(dfl)
print(y)
#> DataFrame with 3 rows and 2 columns
#> a b
#> <integer> <integer>
#> A.aa 1 3
#> A.bb 2 4
#> B.cc 5 6