Search code examples
rtm

selecting list only words witj latin letter in R


Say there is data

text=c(車、,男,犬, sba, druzhba)

How can i get list only with words with latin letter

Here

sba
druzhba

Solution

  • The stringr package can be used for this. See ?"stringi-search-charclass" for details about how to use unicode properties.

    text=c("車","男","犬", "sba", "druzhba")
    
    library(stringr)
    text[str_detect(text, "[\\p{Letter}&&\\p{script=latin}]")]