Identify Non-Numeric Values in Vector or Data Frame Column in R (Example Code)

In this article, I’ll show how to check for non-numeric values in a data object in the R programming language.

Creation of Example Data

my_data <- c("a", 2, 55, "xxx", 7, 8, "6,3")    # Example vector in R
my_data                                         # Display example vector in RStudio
# [1] "a"   "2"   "55"  "xxx" "7"   "8"   "6,3"

Example: Check for Non-Numeric Values Using as.numeric() Function

my_data[which(is.na(as.numeric(my_data)))]
# [1] "a"   "xxx" "6,3"

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top