1

I'm stuck with it, so, please, any advice is welcome.

b <- str_extract_all(c('hello ringпрг','trust'), regex("[a-z]+", TRUE))

Returns a list:

    List of 2
 $ : chr [1:2] "hello" "ring"
 $ : chr "trust"

But I want to have a vector with strings of this words for each element of vector c('hello ringпрг','trust') such as "hello ring", "trust". Any other functions and packages are welcome too.

Shin
  • 251
  • 1
  • 3
  • 8

2 Answers2

2

We can use

unlist(str_extract_all(c('hello ringпрг','trust'), regex("[A-Za-z ]+", TRUE)))
#[1] "hello ring" "trust" 

Or use the pattern as "[[:ascii:]]+"

akrun
  • 874,273
  • 37
  • 540
  • 662
2

Use sapply with paste as in:

b<-str_extract_all(c('hello ringпрг','trust'), regex("[a-z]+", TRUE))

sapply(b, paste, collapse = " ")

## [1] "hello ring" "trust" 
Tyler Rinker
  • 108,132
  • 65
  • 322
  • 519