I want to test a character string and see which elements could actually be numeric. I can use regex to test for integer successful but am looking to see which elements have all digits and 1 or less decimals. Below is what I've tried:
x <- c("0.33", ".1", "3", "123", "2.3.3", "1.2r")
!grepl("[^0-9]", x) #integer test
grepl("[^0-9[\.{0,1}]]", x) # I know it's wrong but don't know what to do
I'm looking for a logical output so I'd expect the following results:
[1] TRUE TRUE TRUE TRUE FALSE FALSE
See Question&Answers more detail:os