Vectorized function for checking if numbers are natural or not. Helps in checking if a vector is of type "order".

is.natural.number(x, tol = .Machine$double.eps^0.5, ...)

Arguments

x

a vector of numbers

tol

tolerence to floating point issues.

...

(not currently in use)

Value

logical - is the entered number natural or not.

Author

Marco Gallotta (a.k.a: marcog), Tal Galili

Examples

is.natural.number(1) # is TRUE
#> [1] TRUE
(x <- seq(-1, 5, by = 0.5))
#>  [1] -1.0 -0.5  0.0  0.5  1.0  1.5  2.0  2.5  3.0  3.5  4.0  4.5  5.0
is.natural.number(x)
#>  [1] FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
#> [13]  TRUE
# is.natural.number( "a" )
all(is.natural.number(x))
#> [1] FALSE