Skip to Content

as.matrix.listOfNamedMatrices {HH}

Convert a list of matrices to a single matrix
Package: 
HH
Version: 
3.0-3

Description

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.

Usage

 
## S3 method for class 'listOfNamedMatrices':
as.matrix((x, abbreviate = TRUE, minlength = 4, ...)
is.listOfNamedMatrices(x,  xName=deparse(substitute(x))))

## S3 method for class 'listOfNamedMatrices':
as.data.frame((x, ...)
as.listOfNamedMatrices(x,  xName=deparse(substitute(x)), ...))

## S3 method for class 'listOfNamedMatrices':
x[(...)]

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

## S3 method for class 'list':
as.listOfNamedMatrices((x, xName=deparse(substitute(x)), ...))

## S3 method for class 'MatrixList':
as.listOfNamedMatrices((x, xName=deparse(substitute(x)), ...))

## S3 method for class 'listOfNamedMatrices':
print((x, ...)

as.MatrixList(x))

## S3 method for class 'array':
as.MatrixList((x))

## S3 method for class 'MatrixList':
print((x, ...)

as.likertDataFrame(x, xName=deparse(substitute(x))))

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

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

Arguments

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.
abbreviate
Logical. If TRUE, then use the abbreviate function on the item names and row names.
minlength
the minimum length of the abbreviations.
xName
Name of the argument in its original environment.

Values

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.

as.data.frame.listOfNamedMatrices(x, ...) 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

likert

Examples

data(ProfChal)
 
tmp <- data.matrix(ProfChal[,1:5])
rownames(tmp) <- ProfChal$Question
ProfChal.list <- split.data.frame(tmp, ProfChal$Subtable)
 
## Original list of matrices is difficult to read because
## it is displayed on too many lines.
ProfChal.list[2:3]
 
## 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]))
tmp3
as.MatrixList(tmp3)
 
 
## Not run:
sapply(as.MatrixList(tmp3), as.likert, simplify=FALSE)  ## odd number of levels.
 
data(NZScienceTeaching)
likert(Question ~ ., NZScienceTeaching)
likert(Question ~ . | Subtable, data=NZScienceTeaching)
likert(Question ~ . | Subtable, data=NZScienceTeaching,
       layout=c(1,2), scales=list(y=list(relation="free")))
## End(Not run)

Author(s)

Richard M. Heiberger

Documentation reproduced from package HH, version 3.0-3. License: GPL (>= 2)