[R] regular expression strikes again
peter dalgaard
pdalgd at gmail.com
Tue Jul 9 11:58:33 CEST 2013
On Jul 9, 2013, at 11:45 , PIKAL Petr wrote:
> 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.
>
Presumably the ^.* is too greedy. Perhaps add a space? I.e.,
gsub("^.* ([[:di......
--
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-help
mailing list