Convert a list of matrices to a single matrix

Convert a list of matrices to a single matrix. This function is used to improve legibility of the printed object. The as.matrix.listOfNamedMatrices display is easier to read when the rownames are very long, as in the example illustrated here. Because the default print of the matrix repeats the rownames several times, with only a few columns of the data shown in each repetition, the actual matrix structure of the data values is obscured.

# S3 method for listOfNamedMatrices
as.matrix(x, abbreviate = TRUE, minlength = 4, ...)
is.listOfNamedMatrices(x,  xName=deparse(substitute(x)))
# S3 method for listOfNamedMatrices, ...)
as.listOfNamedMatrices(x,  xName=deparse(substitute(x)), ...)
# S3 method for listOfNamedMatrices
[(x, ...)
# S3 method for array
as.listOfNamedMatrices(x, xName=deparse(substitute(x)), ...)
# S3 method for list
as.listOfNamedMatrices(x, xName=deparse(substitute(x)), ...)
# S3 method for MatrixList
as.listOfNamedMatrices(x, xName=deparse(substitute(x)), ...)
# S3 method for listOfNamedMatrices
print(x, ...)

as.MatrixList(x) # S3 method for array as.MatrixList(x) # S3 method for MatrixList print(x, ...)

as.likertDataFrame(x, xName=deparse(substitute(x))) # S3 method for listOfNamedMatrices as.likertDataFrame(x, xName=deparse(substitute(x))) # S3 method for array as.likertDataFrame(x, xName=deparse(substitute(x)))


Named list of matrices. All matrices in the list should have the same number of columns and the same column names. The list item names will normally be long. The row names will normally be long. The number of rows and their names will normally differ across the matrices. Each named item in the list may be a vector, matrix, array, data.frame, two-dimensional table, two-dimensional ftable, or two-dimensional structable For the as.MatrixList methods, an array.

Other arguments. Not used.


Logical. If TRUE, then use the abbreviate function on the item names and row names.


the minimum length of the abbreviations.


Name of the argument in its original environment.


The result of as.listOfNamedMatrices is a list with class=c("listOfNamedMatrices", "list").

The result of as.matrix.listOfNamedMatrices is an rbind of the individual matrices in the argument list x. The rownames of the result matrix are constructed by pasting the abbreviation of the list item names with the abbreviation of the individual matrix rownames. The original names are retained as the "Subtables.Rows" attribute.

The result of is.listOfNamedMatrices is logical value.

print.listOfNamedMatrices prints as.matrix.listOfNamedMatrices of its argument and returns the original argument., ...) is an unfortunate kluge. The result is the original x that has NOT been transformed to a data.frame. A warning message is generated that states that the conversion has not taken place. This kluge is needed to use "listOfNamedMatrices" objects with the Commander package because Rcmdr follows its calls to the R data function with an attempt, futile in this case, to force the resulting object to be a data.frame.

The as.MatrixList methods construct a list of matrices from an array. Each matrix has the first two dimensions of the array. The result list is itself an array defined by all but the first two dimensions of the argument array.

See Also


  • as.matrix.listOfNamedMatrices
  • is.listOfNamedMatrices
  • as.listOfNamedMatrices
  • print.listOfNamedMatrices
  • as.MatrixList
  • as.MatrixList.array
  • print.MatrixList
  • matrix
  • [.listOfNamedMatrices
  • as.listOfNamedMatrices.array
  • as.listOfNamedMatrices.list
  • as.listOfNamedMatrices.MatrixList
  • as.likertDataFrame
  • as.likertDataFrame.listOfNamedMatrices
  • as.likertDataFrame.array

tmp <- data.matrix(ProfChal[,1:5])
rownames(tmp) <- ProfChal$Question
ProfChal.list <-, ProfChal$Subtable)

## Original list of matrices is difficult to read because
## it is displayed on too many lines.

## Single matrix with long list item names and long row names
## of argument list retained as an attribute.
as.listOfNamedMatrices(ProfChal.list[2:3], minlength=6)

tmp3 <- array(1:24, dim=c(2,3,4), dimnames=list(A=letters[1:2], B=LETTERS[3:5], C=letters[6:9]))

# }
sapply(as.MatrixList(tmp3), as.likert, simplify=FALSE)  ## odd number of levels.

likert(Question ~ ., NZScienceTeaching)
likert(Question ~ . | Subtable, data=NZScienceTeaching)
likert(Question ~ . | Subtable, data=NZScienceTeaching,
       layout=c(1,2), scales=list(y=list(relation="free")))
# }
Documentation reproduced from package HH, version 3.1-35, License: GPL (>= 2)

Community examples

Looks like there are no examples yet.