Description Usage Arguments Details Value Examples
View source: R/is_positive_integer.R
This function checks if all elements of an object can be taken to be valid integers.
1 | is_positive_integer(x, len = NULL)
|
x |
an object to be checked |
len |
numeric vector specifying the allowed length of the |
The reasons to use is_positive_integer
are:
(1) We often check if an object is a vector of positive integer.
But is.numeric
cannot
do this because it also returns TRUE
for a numeric matrix.
(2) Sometimes is.integer
returns a too strict result. For example, is.integer(3.0)
returns FALSE
,
but the number 3.0 is
valid in codes such as rep(10, 3.0)
, that is to say, as long as a number can be taken
to be a valid integer, we take it to be a integer, even when is.integer
returns FALSE
.
(3) is_positive_integer
returns FALSE
for
length = 0 object, even when it is integer(0)
. To let the function return this result is
because integer of length 0 is a invalid input for many functions.
(4) is_positive_integer
returns FALSE
for any object that contains NA
, so that object that gets a
TRUE
from this function is more likely to be a valid value to be passed to
other functions.
TRUE
or FALSE
1 2 3 4 5 6 7 8 | is_positive_integer(NULL)
is_positive_integer(as.integer(NA))
is_positive_integer(integer(0))
is_positive_integer(3.0)
is_positive_integer(3.3)
is_positive_integer(1:5)
is_positive_integer(1:5, len = c(2, 10))
is_positive_integer(1:5, len = c(2:10))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.