rbind a list of vectors into matrix or data.frame
rbindList(
x,
emptyValue = "",
nullValue = NULL,
keepListNames = TRUE,
newColnames = NULL,
newRownames = NULL,
fixBlanks = TRUE,
returnDF = FALSE,
verbose = FALSE,
...
)
list
of atomic vector
, matrix
, or data.frame
objects.
character
value to use to represent missing values,
whenever a blank cell is introduced into the resulting matrix
optional value used to replace NULL entries in
the input list, useful especially when the data was produced
by strsplit()
with ""
. Use nullValue=""
to replace NULL
with ""
and preserve the original list length. Otherwise when
nullValue=NULL
any empty entries will be silently dropped.
logical
whether to use list names as rownames
in the resulting matrix or data.frame.
NULL or character
vector of colnames to use for the
resulting matrix or data.frame.
NULL or character
vector of rownames to use for the
resulting matrix or data.frame. If supplied, this value overrides the
keepListNames=TRUE use of list names as rownames.
logical
whether to use blank values instead of repeating
each vector to the length of the maximum vector length when filling
each row of the matrix or data.frame.
logical
whether to return a data.frame, by default FALSE,
a matrix is returned.
logical
whether to print verbose output during processing.
matrix
unless returnDF=TRUE
in which the output is coerced
to a data.frame
.
The rownames by default are derived from the list names,
but the colnames are not derived from the vector names.
If input x
contains data.frame
or matrix
objects, the output
will retain those values.
The purpose of this function is to emulate do.call(rbind, x)
on a list
of vectors, while specifically handling when there are different
numbers of entries per vector. The output matrix
number of columns
will be the longest vector (or largest number of columns) in the
input list x
.
Instead of recycling values in each row to fill the target number
of columns, this function fills cells with blank fields,
with default argument fixBlanks=TRUE
.
In extensive timings tests at the time this function was created,
this technique was notably faster than alternatives.
It runs do.call(rbind, x)
then subsequently replaces recycled values
with blank entries, in a manner that is notably faster than
alternative approaches such as pre-processing the input data.
Other jam list functions:
cPasteSU()
,
cPasteS()
,
cPasteUnique()
,
cPasteU()
,
cPaste()
,
heads()
,
jam_rapply()
,
list2df()
,
mergeAllXY()
,
mixedSorts()
,
relist_named()
,
rlengths()
,
sclass()
,
sdim()
,
uniques()
,
unnestList()
L <- list(a=LETTERS[1:4], b=letters[1:3]);
rbindList(L);
#> [,1] [,2] [,3] [,4]
#> a "A" "B" "C" "D"
#> b "a" "b" "c" ""
rbindList(L, returnDF=TRUE);
#> 1 2 3 4
#> a A B C D
#> b a b c