powered by
Test for natural numbers according to ISO 80000-2, that is the set 0, 1, 2, ...
is_natural_number(x)
TRUE in case x is a natural number,
TRUE
x
FALSE otherwise.
FALSE
numeric vector
numeric
stopifnot(!is_natural_number(3.1)) stopifnot(!is_natural_number(2.99)) stopifnot(is_natural_number(3)) stopifnot(all(is_natural_number(0:9))) stopifnot(sum(is_natural_number(c(1, 2.5, 3))) == 2)
Run the code above in your browser using DataLab