Print a Matrix

DESCRIPTION:

Prints a matrix, or a two-dimensional slice of an array.

USAGE:

print.matrix(x, digits = NULL, quote = T, right = F,  
             abbreviate.labels = F, ...) 

REQUIRED ARGUMENTS:

x
a matrix, i.e., length(dim(x)) is 2.

OPTIONAL ARGUMENTS:

digits
used to determine the length to which the column names will be abbreviated if abbreviate.labels is TRUE. If digits is not specified, then the value of .Options$digits is used.
quote
logical flag: if TRUE, character strings are surrounded by quotes.
right
logical flag: if TRUE, the contents of the matrix are right justified in the columns of output. If FALSE, they are left justified.
abbreviate.labels
logical flag: if TRUE, the column labels are abbreviated (using the function abbreviate).

VALUE:

x, with the invisible flag set to prevent reprinting.

SIDE EFFECTS:

print.matrix prints x as a matrix. It is called as a result of automatically printing a matrix or a multi-way array.

DETAILS:

A format is chosen for each column, for each page, so that columns line up. Wide matrices are broken into blocks by choosing as many columns as fit on one line. If x has a "dimnames" attribute, dimnames(x)[[1]] provides row labels, if it has length > 0, and similarly dimnames(x)[[2]] provides column labels. If it has no "dimnames" attribute, row labels are made up to look like row subscripts ( "[1,]", etc.) and column labels are made up to look like column subscripts ( "[,1]", etc).

After each page of output, the column labels are printed again, so that there should always be a copy of the column labels on the screen at any time. To avoid multiple copies of the column labels, execute options(length=10000) to specify a very long page. A new format may be chosen at the end of each page.

When x is atomic, print.matrix allows further control over the format of the column labels. If abbreviate.labels is TRUE, then the column labels are printed in a shortened form created by the function abbreviate. The minimum length ( minlength) argument of abbreviate is determined by digits if x is of mode numeric, 2 times digits if x is complex, or 3 more than the length of the longest element of x if x is a character matrix.

If x is not atomic, quote is always FALSE, and abbreviate.labels is not used.

SEE ALSO:

, , , , , , .

EXAMPLES:

state.x77[, 1:4] 
# produces the following output: 
              Population Income Illiteracy Life Exp 
      Alabama       3615   3624        2.1    69.05 
       Alaska        365   6315        1.5    69.31 
      Arizona       2212   4530        1.8    70.55 
... 
print.matrix(state.x77[,1:8], digits = 3, abb = T) 
          Ppl  Inc Ill   LEx  Mrd  HSG Frs    Are 
 Alabama 3615 3624 2.1 69.05 15.1 41.3  20  50708 
...