Learn R Programming

sfsmisc (version 1.1-19)

is.whole: Test Whether a Vector or Array Consists of Whole Numbers

Description

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).

Usage

is.whole(x, tolerance = sqrt(.Machine$double.eps))

Value

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.

Arguments

x

integer, numeric, or complex vector or array to be tested

tolerance

maximal distance to the next whole number

Author

Alain Hauser <alain@huschhus.ch>

See Also

Examples

Run this code
## 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))

Run the code above in your browser using DataLab