Reputation: 2834
I am currently in the process of doing some text analysis. I want to keep only alphanumeric characters but for some reason I am having trouble removing some pesky characters that I don't consider alphanumeric. Here's an example of what I am dealing with:
letters <- "ՄĄՄdasdas"
letters <- gsub("[^[:alnum:]]", "",letters)
letters
> "ՄĄՄdasdas"
What am I doing wrong here?
Upvotes: 4
Views: 417
Reputation: 44614
@konvas shows you how to use gsub
correctly in this situation. The problem with your attempt is that those non-ASCII characters are considered alphabetic characters in your locale. Another option is to use iconv
:
iconv(letters, to='ASCII', sub='')
Upvotes: 6