as.matrix.listOfMatrices: Convert a list of numeric matrices to a single matrix

as.matrix.listOfNamedMatricesR Documentation

Convert a list of numeric matrices to a single matrix

Description

Convert a list of numeric 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 numeric matrices. All matrices in the list should have the same number of columns and the same column names. The names of the list items will normally be long; NA, as introduced by the addNA, is a valid name. 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.

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.

Author(s)

Richard M. Heiberger <rmh@temple.edu>

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)

## Not run: 
## NA as a dimname value
tmp <- structure(c(0, 0, 0, 6293, 18200, 2122,
                   0, 0, 0, 2462, 7015, 5589, 
                   6908, 5337, 842, 0, 0, 0),
                 .Dim = c(3L, 2L, 3L),
                 .Dimnames = list(c("A", "B", "C"),
                                  c("D", "E"),
                                  c("F", "G", NA)))
tmp
as.MatrixList(tmp)

## End(Not run)

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

HH documentation built on May 29, 2024, 6:24 a.m.