[R] test if elements of a character vector contain letters

Liviu Andronic landronimirc at gmail.com
Wed Aug 8 07:40:04 CEST 2012


On Tue, Aug 7, 2012 at 10:18 PM, Marc Schwartz <marc_schwartz at me.com> wrote:
> That will get you values where punctuation characters are used, but there may be other non-alphanumeric characters in the vector. There may be ASCII control codes, tabs, newlines, CR, LF, spaces, etc. which would not be found by using [:punct:].
>
> For example:
>
>> grepl("[[:punct:]]", " ")
> [1] FALSE
>
>
> If you want to explicitly look for non-alphanumeric characters, you would be better off using a negation of [:alnum:] such as:
>
[..]

>
> !grepl("[[:alnum:]]", x)
>
Good point! Thanks.
Liviu



More information about the R-help mailing list