#' Find and return values that look non-numeric
#'
#' @param xx input vector
#'
#' @return logical vector the same length as `xx` indicating whether values convert to numeric or not
#' @export
#'
#' @examples
#' str_is_numeric( as.factor( c( 'a', 1:5, NA) ) )
str_is_numeric <- function(xx){
if( is.numeric(xx) ){
return( TRUE )
} else {
if( is.factor(xx) ) xx = as.character(xx)
prena = is.na( xx )
postna = is.na( suppressWarnings(as.numeric(xx)) )
return( !(postna & !prena) )
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.