using \\d
works for me:
grepl("\\d", mywords)
[1] FALSE FALSE FALSE TRUE TRUE TRUE
so does [[:digit:]]
:
grepl("[[:digit:]]", mywords)
[1] FALSE FALSE FALSE TRUE TRUE TRUE
As @nrussel mentionned, you're testing if the strings contain only digits between the beginning ^
of the string till the end $
.
You could also check if the strings contain something else than letters, using ^
inside brackets to negate the letters, but then "something else" is not only digits:
grepl("[^a-zA-Z]", mywords)
[1] FALSE FALSE FALSE TRUE TRUE TRUE