[R] test if elements of a character vector contain letters
Liviu Andronic
landronimirc at gmail.com
Wed Aug 8 10:56:32 CEST 2012
On Tue, Aug 7, 2012 at 10:26 PM, Marc Schwartz <marc_schwartz at me.com> wrote:
> since there are alpha-numerics present, whereas the first option will:
>
>> grepl("[^[:alnum:]]", "ab%")
> [1] TRUE
>
>
> So, use the first option.
>
And I should start reading more carefully. The above works fine for me.
I ended up defining the following wrappers:
is_alpha <- function(x) {grepl("[[:alpha:]]", x)} ##Alphabetic characters
is_digit <- function(x) {grepl("[[:digit:]]", x)} ##Digits
is_alnum <- function(x) {grepl("[[:alnum:]]", x)} ##Alphanumeric characters
is_punct <- function(x) {grepl("[[:punct:]]", x)} ##Punctuation characters
is_notalnum <- function(x) {grepl("[^[:alnum:]]", x)}
##Non-Alphanumeric characters
Thanks again
Liviu
More information about the R-help
mailing list