| 1 |
\name{is.whole} |
| 2 |
\alias{is.whole} |
| 3 |
\title{Test Whether a Vector or Array Consists of Whole Numbers} |
| 4 |
\description{ |
| 5 |
This function tests whether a \code{numeric} or \code{complex} vector |
| 6 |
or array consists of whole numbers. The function \code{\link{is.integer}} |
| 7 |
is not appropriate for this since it tests whether the vector is of class |
| 8 |
\code{integer} (see examples). |
| 9 |
} |
| 10 |
\usage{ |
| 11 |
is.whole(x, tolerance = sqrt(.Machine$double.eps)) |
| 12 |
} |
| 13 |
\arguments{ |
| 14 |
\item{x}{\code{integer}, \code{numeric}, or \code{complex} vector or |
| 15 |
array to be tested} |
| 16 |
\item{tolerance}{maximal distance to the next whole number} |
| 17 |
} |
| 18 |
% \details{ |
| 19 |
%% ~~ If necessary, more details than the description above ~~ |
| 20 |
% } |
| 21 |
\value{ |
| 22 |
The return value has the same dimension as the argument \code{x}: if \code{x} |
| 23 |
is a vector, the function returns a \code{logical} vector of the same length; |
| 24 |
if \code{x} is a matrix or array, the function returns a \code{logical} matrix |
| 25 |
or array of the same dimensions. Each entry in the result indicates whether |
| 26 |
the corresponding entry in \code{x} is whole. |
| 27 |
} |
| 28 |
\author{Alain Hauser <[email protected]>} |
| 29 |
\seealso{\code{\link{is.integer}}} |
| 30 |
\examples{ |
| 31 |
## Create a random array, matrix, vector |
| 32 |
set.seed(307) |
| 33 |
a <- array(runif(24), dim = c(2, 3, 4)) |
| 34 |
a[4:8] <- 4:8 |
| 35 |
m <- matrix(runif(12), 3, 4) |
| 36 |
m[2:4] <- 2:4 |
| 37 |
v <- complex(real = seq(0.5, 1.5, by = 0.1), |
| 38 |
imaginary = seq(2.5, 3.5, by = 0.1)) |
| 39 |
|
| 40 |
## Find whole entries |
| 41 |
is.whole(a) |
| 42 |
is.whole(m) |
| 43 |
is.whole(v) |
| 44 |
|
| 45 |
## Numbers of class integer are always whole |
| 46 |
is.whole(dim(a)) |
| 47 |
is.whole(length(v)) |
| 48 |
} |
| 49 |
\keyword{arith} |