Split sentence by words with regex in R -


i'm using (or i'd use) r extract information. have following sentence , i'd split. in end, i'd extract number 24.

here's have:

doc <- "hits  1 - 10 24" 

and want extract number "24". know how extract number once can reduce sentence in "hits 1 - 10 from" , "24". tried using this:

n_docs <- unlist(str_split(key_n_docs, ".\\from"))[1] 

but leaves me with: "hits 1 - 10" split works somehow, i'm interested in part after "from" not 1 before. appreciated!

if want extract single character string:

strsplit(key_n_docs, "from")[[1]][2] 

or equivalent expression used @bastim (sorry saw answer after submitted mine)

unlist(strsplit(key_n_docs, "from"))[2] 

if want extract vector of character strings:

sapply(strsplit(key_n_docs, "from"),`[`, 2) 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -