stri_list2matrix {stringi} | R Documentation |
This function converts a given list of atomic vectors to a character matrix.
stri_list2matrix(x, byrow = FALSE, fill = NA_character_, n_min = 0)
x |
a list of atomic vectors |
byrow |
single logical value; should the resulting matrix be transposed? |
fill |
single string, see Details |
n_min |
single integer value; minimal number of rows ( |
This function is similar to the built-in simplify2array
function. However, it always returns a character matrix,
even if each element in x
is of length 1
or if elements in x
are not of the same lengths.
Moreover, the elements in x
are always coerced to character vectors.
If byrow
is FALSE
, then a matrix with length(x)
columns is returned.
The number of rows is the length of the
longest vector in x
, but no less than n_min
. Basically, we have
result[i,j] == x[[j]][i]
if i <= length(x[[j]])
and result[i,j] == fill
otherwise, see Examples.
If byrow
is TRUE
, then the resulting matrix is
a transposition of the above-described one.
This function may be useful e.g. in connection with stri_split
and stri_extract_all
.
Always returns a character matrix.
simplify2array(list(c("a", "b"), c("c", "d"), c("e", "f"))) stri_list2matrix(list(c("a", "b"), c("c", "d"), c("e", "f"))) stri_list2matrix(list(c("a", "b"), c("c", "d"), c("e", "f")), byrow=TRUE) simplify2array(list("a", c("b", "c"))) stri_list2matrix(list("a", c("b", "c"))) stri_list2matrix(list("a", c("b", "c")), fill="") stri_list2matrix(list("a", c("b", "c")), fill="", n_min=5)