as.array3 | R Documentation |
Coerce a vector or array to have 3 dimensions, preserving dimnames if feasible. Throw an error if length(dim(x)) > 3.
as.array3(x)
x |
A vector or array. |
1. dimx <- dim(x); ndim <- length(dimx)
2. if(ndim==3)return(x).
3. if(ndim>3)stop.
4. x2 <- as.matrix(x)
5. dim(x2) <- c(dim(x2), 1)
6. xnames <- dimnames(x)
7. if(is.list(xnames))dimnames(x2) <- list(xnames[[1]], xnames[[2]], NULL)
A 3-dimensional array with names matching x
Spencer Graves
Ramsay, James O., Hooker, Giles, and Graves, Spencer (2009), Functional data analysis with R and Matlab, Springer, New York.
Ramsay, James O., and Silverman, Bernard W. (2005), Functional Data Analysis, 2nd ed., Springer, New York.
Ramsay, James O., and Silverman, Bernard W. (2002), Applied Functional Data Analysis, Springer, New York.
dim
,
dimnames
checkDims3
##
## vector -> array
##
as.array3(c(a=1, b=2))
##
## matrix -> array
##
as.array3(matrix(1:6, 2))
as.array3(matrix(1:6, 2, dimnames=list(letters[1:2],
LETTERS[3:5])))
##
## array -> array
##
as.array3(array(1:6, 1:3))
##
## 4-d array
##
# These lines throw an error because the dimensionality woud be 4
# and as.array3 only allows dimensions 3 or less.
# if(!CRAN()) {
# as.array3(array(1:24, 1:4))
# }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.