Removing odd characters in R with gsub

I am currently analyzing the text. I want to save only alphanumeric characters, but for some reason I am having problems deleting some annoying characters that I don't consider alphanumeric. Here is an example of what I mean:

letters <- "ՄĄՄdasdas"
letters <- gsub("[^[:alnum:]]", "",letters)   
letters

> "ՄĄՄdasdas"

What am I doing wrong here?

+4
source share
2 answers

@konvas shows you how to use it correctly gsubin this situation. The problem with your attempt is that these non-ASCII characters are considered alphabetical characters in your locale. Another option is to use iconv:

iconv(letters, to='ASCII', sub='')
+6
source

Try gsub("[^A-Za-z0-9]", "", letters)

+3

All Articles