is.whole.RdThis 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))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.
## 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)
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] FALSE FALSE TRUE
#> [2,] FALSE TRUE TRUE
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] TRUE FALSE FALSE
#> [2,] TRUE FALSE FALSE
#>
#> , , 3
#>
#> [,1] [,2] [,3]
#> [1,] FALSE FALSE FALSE
#> [2,] FALSE FALSE FALSE
#>
#> , , 4
#>
#> [,1] [,2] [,3]
#> [1,] FALSE FALSE FALSE
#> [2,] FALSE FALSE FALSE
#>
is.whole(m)
#> [,1] [,2] [,3] [,4]
#> [1,] FALSE TRUE FALSE FALSE
#> [2,] TRUE FALSE FALSE FALSE
#> [3,] TRUE FALSE FALSE FALSE
is.whole(v)
#> [1] FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE
## Numbers of class integer are always whole
is.whole(dim(a))
#> [1] TRUE TRUE TRUE
is.whole(length(v))
#> [1] TRUE