#' Nombre entier
#'
#' Indique si la valeur est un nombre entier.
#'
#' R fait la différence entre un `integer` et un `numeric`. Par exemple, `is.integer(1) = FALSE`, mais `is.integer(1L) = TRUE`.
#'
#' @param x Vecteur de type `numeric`.
#'
#' @return `Logical`
#' @export
#'
#' @examples
#' is.wholenumber(5) # numeric - TRUE
#' is.wholenumber(5L) # integer - TRUE
#' is.wholenumber(5.5) # numeric - FALSE
#' is.wholenumber(1:10) # plusieurs valeurs - TRUE
#' is.wholenumber(c(1:10, 11.1)) # plusieurs valeurs - FALSE
is_wholenumber <- function(x){
if(!is.numeric(x))
stop("x n'est pas de type NUMERIC.")
return( # indique si toutes les valeurs sont des nombres entiers
all(sapply(x, function(x){
return(x - round(x) == 0)
}))
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.