-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathas.array3.Rd
87 lines (73 loc) · 1.65 KB
/
as.array3.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
\name{as.array3}
\alias{as.array3}
\alias{as.array3}
\title{
Reshape a vector or array to have 3 dimensions.
}
\description{
Coerce a vector or array to have 3 dimensions, preserving dimnames if
feasible. Throw an error if length(dim(x)) > 3.
}
\usage{
as.array3(x)
}
\arguments{
\item{x}{
A vector or array.
}
}
\details{
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)
}
\value{
A 3-dimensional array with names matching \code{x}
}
\references{
Ramsay, James O., Hooker, Giles, and Graves, Spencer (2009),
\emph{Functional data analysis with R and Matlab}, Springer, New
York.
Ramsay, James O., and Silverman, Bernard W. (2005), \emph{Functional
Data Analysis, 2nd ed.}, Springer, New York.
Ramsay, James O., and Silverman, Bernard W. (2002), \emph{Applied
Functional Data Analysis}, Springer, New York.
}
\author{
Spencer Graves
}
\seealso{
\code{\link{dim}},
\code{\link{dimnames}}
\code{\link{checkDims3}}
}
\examples{
##
## 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))
# }
}
\keyword{utilities}