I would like to print a matrix without column names and found this answer. However, this will result in the columns of the output not being aligned anymore, when the row names are kept and are of different length:
m <- matrix(LETTERS[1:12],nrow = 2, ncol = 6)
rownames(m) <- c("First Row", "Second Row")
Using print just ignores the col.names = FALSE argument (why?):
print(m, col.names=FALSE, quote=FALSE)
> [,1] [,2] [,3] [,4] [,5] [,6]
> First Row A C E G I K
> Second Row B D F H J L
Using write.table as proposed removes the alignment:
write.table(format(m, justify="right"), col.names=FALSE, quote=FALSE)
> First Row A C E G I K
> Second Row B D F H J L
What can I do to keep row names and the alignment intact?