Skip to content
Prev 245225 / 398503 Next

Numbers in a string

On Fri, Dec 17, 2010 at 07:39:46AM -0500, Gabor Grothendieck wrote:
[...]
I am sorry for overlooking this solution using package gsubfn, although
it was pointed out repeatedly in this thread. The following solves
exactly the example i was asking for.

  library(gsubfn) 
  s <- "abcde. 11 abc 5.31e+34, (1.45)"
  strapply(s, "[0-9]+\\.[0-9]+e[+-][0-9]+|[0-9]+\\.[0-9]+|[0-9]+")[[1]]
  [1] "11"       "5.31e+34" "1.45"

Thank you for this information.

Petr Savicky.