[R] find numbers in a line with letters

Gabor Grothendieck ggrothendieck at gmail.com
Thu Aug 27 00:46:30 CEST 2009


Try this:

library(gsubfn)
s <- "this item costs 3.32 Dollars"
strapply(s, "[0-9][0-9.]*", as.numeric)[[1]]

See http://gsubfn.googlecode.com for more info.

On Wed, Aug 26, 2009 at 6:38 PM, Martin Batholdy<batholdy at googlemail.com> wrote:
> hi,
>
> is there an easy way to extract numbers from a string?
>
> for example I have;
> "this Item costs 3.32 Dollars"
>
> is there an easy way to extract the 3.32 as a number?
>
>
> thanks!
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list