one way is the following:
mat <- matrix(1:12, 3, 4, TRUE)
dimnames(mat) <- list(c("A", "E", "F"), LETTERS[1:4])
cnams <- colnames(mat)
rnams <- rownames(mat)
unq.nams <- unique(c(cnams, rnams))
out <- matrix(0, length(unq.nams), length(unq.nams),
dimnames = list(unq.nams, unq.nams))
p1 <- pa
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
I have a rectangular matrix of size 920 by 85. I'd like to coerce it into a
square matrix such that all row/col names are present in the new matrix and the
additional values are zero.
As an example:
A B C D
A 1 2 3 4
E 5 6 7 8
F 9 10 1
2 matches
Mail list logo