View source: R/str2str_functions.R
cbind_fill_matrix | R Documentation |
cbind_fill_matrix
binds together matrix-like objects by columns. The input
objects will all internally be converted to matrices by the generic function
as.matrix
. When some objects do not contain rows that are present in other
objects, NAs will be added to fill up the returned combined matrix. If a matrix
doesn't have rownames, the row number is used. Note that this means that a row
with name "1" is merged with the first row of a matrix without name and so on.
The returned matrix will always have row names. Colnames are ignored.
cbind_fill_matrix(...)
... |
any combination of matrices, data.frames, or atomic vectors input as separate arguments or a list. |
cbind_fill_matrix
is t.default
+ plyr::rbind.fill.matrix
+ t.default
and is based on the code within plyr::rbind.fill.matrix
.
matrix created by combining all the objects input together. It will always
have rownames. It will only have colnames if ...
is a list of vectors,
in which the colnames will be the names of the list.
cbind_fill
rbind.fill.matrix
# standard use
A <- matrix(1:4, 2)
B <- matrix(6:11, 3)
print(A)
print(B)
cbind_fill_matrix(A, B)
# help with unstack()
row_keep <- sample(1:nrow(InsectSprays), size = 36)
InsectSprays2 <- InsectSprays[row_keep, ]
unstacked <- unstack(InsectSprays2)
cbind_fill_matrix(unstacked)
# using rownames for binding
rownames(A) <- c("one", "two")
rownames(B) <- c("three","two","one")
print(A)
print(B)
cbind_fill_matrix(A, B)
# data.frame input
C <- data.frame("V1" = c(12,13,14,15), row.names = c("one","two","three","four"))
print(C)
cbind_fill_matrix(A, B, C)
# atomic vector input
A <- matrix(1:4, 2)
B <- matrix(6:11, 3)
C <- c(12,13,14,15)
cbind_fill_matrix(A, B, C)
# same as plyr::rbind.fill.matrix, cbind_fill_matrix doesn't like some input
# with dimnames and others without...
rownames(A) <- c("one", "two")
print(A)
print(B)
cbind_fill_matrix(A, B)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.