Skip to content
Back to formatted view

Raw Message

Message-ID: <CABxs9VnnCSSfN55ezJE9Zs_n0XUoLf7yTWr=ZO4GqsRbUDPCQg@mail.gmail.com>
Date: 2012-08-08T08:56:32Z
From: Liviu Andronic
Subject: test if elements of a character vector contain letters
In-Reply-To: <ED08ED7E-3D26-4DA8-B4CD-C9C13216C3FE@me.com>

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