| Line 1... |
Line 1... |
| 1 |
% File src/library/base/man/drop.Rd
|
1 |
% File src/library/base/man/drop.Rd
|
| 2 |
% Part of the R package, https://www.R-project.org
|
2 |
% Part of the R package, https://www.R-project.org
|
| 3 |
% Copyright 1995-2021 R Core Team
|
3 |
% Copyright 1995-2024 R Core Team
|
| 4 |
% Distributed under GPL 2 or later
|
4 |
% Distributed under GPL 2 or later
|
| 5 |
|
5 |
|
| 6 |
\name{drop}
|
6 |
\name{drop}
|
| 7 |
\alias{drop}
|
7 |
\alias{drop}
|
| 8 |
\title{Drop Redundant Extent Information}
|
8 |
\title{Drop Redundant Extent Information}
|
| Line 19... |
Line 19... |
| 19 |
If \code{x} is an object with a \code{dim} attribute (e.g., a matrix
|
19 |
If \code{x} is an object with a \code{dim} attribute (e.g., a matrix
|
| 20 |
or \code{\link{array}}), then \code{drop} returns an object like
|
20 |
or \code{\link{array}}), then \code{drop} returns an object like
|
| 21 |
\code{x}, but with any extents of length one removed. Any
|
21 |
\code{x}, but with any extents of length one removed. Any
|
| 22 |
accompanying \code{dimnames} attribute is adjusted and returned with
|
22 |
accompanying \code{dimnames} attribute is adjusted and returned with
|
| 23 |
\code{x}: if the result is a vector the \code{names} are taken from
|
23 |
\code{x}: if the result is a vector the \code{names} are taken from
|
| 24 |
the \code{dimnames} (if any). If the result is a length-one vector,
|
24 |
the \code{dimnames} (if any). However, if the result is a vector
|
| 25 |
the names are taken from the first dimension with a \I{dimname}.
|
25 |
of length one, then it does not get \code{names} \emph{unless} exactly
|
| - |
|
26 |
one component of the \code{dimnames} is non-\code{NULL}, in which case
|
| - |
|
27 |
that component is used.
|
| 26 |
|
28 |
|
| 27 |
Array subsetting (\code{\link{[}}) performs this reduction unless used
|
29 |
Array subsetting (\code{\link{[}}) performs this reduction unless used
|
| 28 |
with \code{drop = FALSE}, but sometimes it is useful to invoke
|
30 |
with \code{drop = FALSE}, but sometimes it is useful to invoke
|
| 29 |
\code{drop} directly.
|
31 |
\code{drop} directly.
|
| 30 |
}
|
32 |
}
|
| Line 32... |
Line 34... |
| 32 |
\code{\link{drop1}} which is used for dropping terms in models, and
|
34 |
\code{\link{drop1}} which is used for dropping terms in models, and
|
| 33 |
\code{\link{droplevels}} used for dropping unused levels from a \code{\link{factor}}.
|
35 |
\code{\link{droplevels}} used for dropping unused levels from a \code{\link{factor}}.
|
| 34 |
}
|
36 |
}
|
| 35 |
\examples{
|
37 |
\examples{
|
| 36 |
dim(drop(array(1:12, dim = c(1,3,1,1,2,1,2)))) # = 3 2 2
|
38 |
dim(drop(array(1:12, dim = c(1,3,1,1,2,1,2)))) # = 3 2 2
|
| 37 |
drop(1:3 \%*\% 2:4) # scalar product
|
39 |
drop(1:3 \%*\% 2:4) # scalar product - w/o drop(.), would return 1x1 matrix
|
| - |
|
40 |
|
| - |
|
41 |
# Behavior when result is length-1 vector:
|
| - |
|
42 |
(x <- x1 <- x2 <- array(0, c(1L, 1L), list("a", "b")))
|
| - |
|
43 |
colnames(x1) <- rownames(x2) <- NULL
|
| - |
|
44 |
names(drop(x )) # NULL
|
| - |
|
45 |
names(drop(x1)) # "a"
|
| - |
|
46 |
names(drop(x2)) # "b"
|
| 38 |
}
|
47 |
}
|
| 39 |
\keyword{array}
|
48 |
\keyword{array}
|