HH (version 3.1-19)

as.matrix.listOfNamedMatrices: Convert a list of matrices to a single matrix

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 no
...
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.

Value

  • 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

Run this code
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)

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")))

Run the code above in your browser using DataCamp Workspace