Description Usage Arguments Value Note Author(s) Examples
Transforms a list of scalars, vectors, or matrices into a simplified structure with one additional dimension (i.e. a vector, matrix, or 3D array).
1 | simplifyList(L)
|
L |
List to be transformed. All elements of |
The returned type depends on the type of the elements of L
.
scalar case: If each element of L
is a scalar, the result
is a vector of length length(L)
.
vector case: If each element of L
is a vector, the result
is a matrix. The number of rows equals length(L)
and the number
of columns is determined by the length of the vectors, i.e.
length(L[[1]])
.
matrix case: If each element of L
is a matrix, the result
is an array with 3 dimensions. The length of dimension 1 equals the
number of the matrices' rows, the length of dimension 2 equals the
number of the matrices' columns, and the length of the 3rd dimension is
length(L)
.
An error is generated if the restrictions with respect to the elements
of L
are not met.
David Kneis david.kneis@tu-dresden.de
1 2 3 4 5 6 7 8 9 10 11 12 | # List of scalars
x= list(a=1, b=2, c=3)
print(simplifyList(x)) # same as unlist(x)
# List of vectors
x= list(a=1:2, b=2:3, c=3:4)
print(simplifyList(x))
# List of matrices
m= matrix(1:6, ncol=2)
colnames(m)= paste0("col",1:ncol(m))
rownames(m)= paste0("row",1:nrow(m))
x= list(a=m*1, b=m*2, c=m*3)
print(simplifyList(x))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.