[R] regular expression strikes again

PIKAL Petr petr.pikal at precheza.cz
Tue Jul 9 11:45:55 CEST 2013


Dear experts in regexpr.

I have this

dput(test[500:510])
c("pH 9,36 2", "pH 9,36 3", "pH 9,66 1", "pH 9,66 2", "pH 9,66 3", 
"pH 10,04 1", "pH 10,04 2", "pH 10,04 3", "RGLP 144006 pH 6,13 1", 
"RGLP 144006 pH 6,13 2", "RGLP 144006 pH 6,13 3")

and I want something like this

gsub("^.*([[:digit:]],[[:digit:]]*).*$", "\\1", test[500:510])
 [1] "9,36" "9,36" "9,66" "9,66" "9,66" "0,04" "0,04" "0,04" "6,13" "6,13"
[11] "6,13"

but with 10,04 values instead of 0,04.

I tried
gsub("^.*([[:digit:]]+,[[:digit:]]*).*$", "\\1", test[500:510])

or other variations but without any success.

Please help.

Regards
Petr



More information about the R-help mailing list