Re: [R] Extracting numeric part from a string

2017-08-02 Thread Marc Schwartz
Thanks Bert. I should probably also explicitly mention that if Christofer wants to ultimately coerce the numeric components of the strings to numeric data types for subsequent mathematical operations, you will need to strip the commas anyway. In that case, my first response, where I did not i

Re: [R] Extracting numeric part from a string

2017-08-02 Thread Bert Gunter
... and Marc's solution is **much** better than mine. -- Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, Aug 2, 2017 at 5:59 PM, Bert Gunter wrote: >

Re: [R] Extracting numeric part from a string

2017-08-02 Thread Bert Gunter
... Or if you just want to stick with basic regex's without extra packages: > x <- "\"cm_ffm\":\"563.77\"" > sub("[^[:digit:]]*([[:digit:]]*.?[[:digit:]]*).*","\\1",x) [1] "563.77" Cheers, Bert On Wed, Aug 2, 2017 at 5:16 PM, Ismail SEZEN wrote: > >> On 3 Aug 2017, at 02:59, Christofer Bogas

Re: [R] Extracting numeric part from a string

2017-08-02 Thread Marc Schwartz
> On Aug 2, 2017, at 7:42 PM, Marc Schwartz wrote: > > >> On Aug 2, 2017, at 6:59 PM, Christofer Bogaso >> wrote: >> >> Hi again, >> >> I am struggling to extract the number part from below string : >> >> "\"cm_ffm\":\"563.77\"" >> >> Basically, I need to extract 563.77 from above. The un

Re: [R] Extracting numeric part from a string

2017-08-02 Thread Marc Schwartz
> On Aug 2, 2017, at 6:59 PM, Christofer Bogaso > wrote: > > Hi again, > > I am struggling to extract the number part from below string : > > "\"cm_ffm\":\"563.77\"" > > Basically, I need to extract 563.77 from above. The underlying number > can be a whole number, and there could be comma se

Re: [R] Extracting numeric part from a string

2017-08-02 Thread Ismail SEZEN
> On 3 Aug 2017, at 02:59, Christofer Bogaso > wrote: > > Hi again, > > I am struggling to extract the number part from below string : > > "\"cm_ffm\":\"563.77\"" > > Basically, I need to extract 563.77 from above. The underlying number > can be a whole number, and there could be comma separ

[R] Extracting numeric part from a string

2017-08-02 Thread Christofer Bogaso
Hi again, I am struggling to extract the number part from below string : "\"cm_ffm\":\"563.77\"" Basically, I need to extract 563.77 from above. The underlying number can be a whole number, and there could be comma separator as well. So far I tried below : > library(stringr) > str_extract("\"