Test Whether a Vector or Array Consists of Whole Numbers
This function tests whether a numeric
or complex
vector
or array consists of whole numbers. The function is.integer
is not appropriate for this since it tests whether the vector is of class
integer
(see examples).
is.whole(x, tolerance = sqrt(.Machine$double.eps))
x |
|
tolerance |
maximal distance to the next whole number |
The return value has the same dimension as the argument x
: if x
is a vector, the function returns a logical
vector of the same length;
if x
is a matrix or array, the function returns a logical
matrix
or array of the same dimensions. Each entry in the result indicates whether
the corresponding entry in x
is whole.
Alain Hauser <alain@huschhus.ch>
## Create a random array, matrix, vector set.seed(307) a <- array(runif(24), dim = c(2, 3, 4)) a[4:8] <- 4:8 m <- matrix(runif(12), 3, 4) m[2:4] <- 2:4 v <- complex(real = seq(0.5, 1.5, by = 0.1), imaginary = seq(2.5, 3.5, by = 0.1)) ## Find whole entries is.whole(a) is.whole(m) is.whole(v) ## Numbers of class integer are always whole is.whole(dim(a)) is.whole(length(v))
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.