Last data update: 2014.03.03

R: Is Object Numeric and Whole Numbers
is.wholenumberR Documentation

Is Object Numeric and Whole Numbers

Description

Checks whether an object is numeric and if so, are all the elements whole numbers, to a given tolerance.

Usage

is.wholenumber(x, tolerance = .Machine$double.eps^0.5)

Arguments

x

The object to be tested.

tolerance

Numeric >=0. Absolute differences greater than tolerance are treated as real differences.

Details

The object x is first tested to see if it is numeric. If not the function returns 'FALSE'. Then if all the elements of x are whole numbers to within the tolerance given by tolerance the function returns 'TRUE'. If not it returns 'FALSE'.

Value

Either 'TRUE' or 'FALSE' depending on the result of the test.

Author(s)

David Scott d.scott@auckland.ac.nz.

References

Based on a post by Tony Plate <tplate@acm.org> on R-help.

Examples

is.wholenumber(-3:5)                           # TRUE
is.wholenumber(c(0,0.1,1.3,5))                 # FALSE
is.wholenumber(-3:5 + .Machine$double.eps)     # TRUE
is.wholenumber(-3:5 + .Machine$double.eps^0.5) # FALSE
is.wholenumber(c(2L,3L))                       # TRUE
is.wholenumber(c("2L","3L"))                   # FALSE
is.wholenumber(0i ^ (-3:3))                    # FALSE
is.wholenumber(matrix(1:6, nrow = 3))          # TRUE
is.wholenumber(list(-1:3,2:6))                 # FALSE
is.numeric(list(-1:3,2:6))                     # FALSE
is.wholenumber(unlist(list(-1:3,2:6)))         # TRUE

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(DistributionUtils)
Loading required package: RUnit
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/DistributionUtils/is.wholenumber.Rd_%03d_medium.png", width=480, height=480)
> ### Name: is.wholenumber
> ### Title: Is Object Numeric and Whole Numbers
> ### Aliases: is.wholenumber
> ### Keywords: classes
> 
> ### ** Examples
> 
> is.wholenumber(-3:5)                           # TRUE
[1] TRUE
> is.wholenumber(c(0,0.1,1.3,5))                 # FALSE
[1] FALSE
> is.wholenumber(-3:5 + .Machine$double.eps)     # TRUE
[1] TRUE
> is.wholenumber(-3:5 + .Machine$double.eps^0.5) # FALSE
[1] FALSE
> is.wholenumber(c(2L,3L))                       # TRUE
[1] TRUE
> is.wholenumber(c("2L","3L"))                   # FALSE
[1] FALSE
> is.wholenumber(0i ^ (-3:3))                    # FALSE
[1] FALSE
> is.wholenumber(matrix(1:6, nrow = 3))          # TRUE
[1] TRUE
> is.wholenumber(list(-1:3,2:6))                 # FALSE
[1] FALSE
> is.numeric(list(-1:3,2:6))                     # FALSE
[1] FALSE
> is.wholenumber(unlist(list(-1:3,2:6)))         # TRUE
[1] TRUE
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>