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" |
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" |
my_data[which(is.na(as.numeric(my_data)))] # [1] "a" "xxx" "6,3"