[R] How to cut data elements included in a text line

Gabor Grothendieck ggrothendieck at gmail.com
Fri Jul 18 20:46:12 CEST 2008


strapply in gsubfn finds matches of the indicated regexp,
in this case a \t followed by one or more minus, dot or digit,
and with backref of -1 it passes the backreference, i.e. portion
of the match within (..), to the function in the third arg.  See
http://gsubfn.googlecode.com

library(gsubfn)
strapply(x, "\t([-.0-9]+)", as.numeric, backref = -1)[[1]]


On Fri, Jul 18, 2008 at 12:44 PM, Christine A.
<adrion at ibe.med.uni-muenchen.de> wrote:
>
> Hello,
>
> assume I have an "unstructured" text line from a connection. Unfortunately,
> it is in string format:
>
> R> x
> [1] "\talpha0\t-0.638\t0.4043\t0.4043\t-2.215\t-0.5765\t-0.137\t501\t2000"
>
>
> How can I extract the data included in this string object "x" in order to
> get the elements for the parameter vector called "alpha0", i.e.
>  -0.638   0.4043   0.0467  0.4043 -2.215  -0.5765  -0.137 501
>
>
> Any hints how to handle this would be appreciated.
> Best regards,
> Christine
>
>
> --
> Christine Adrion, Dipl.-Stat., MPH
>
> Ludwig-Maximilians-Universitaet Muenchen
> IBE  - Institut fuer Medizinische Informations-
> verarbeitung, Biometrie und Epidemiologie
> Marchioninistr. 15
> D- 81377 Muenchen
>
> Tel.:      +49 (0)89 7095 - 4483
> eMail:    adrion at ibe.med.uni-muenchen.de
> web:     http://ibe.web.med.uni-muenchen.de
>
>
>
>
>
>
>
>
> --
> View this message in context: http://www.nabble.com/How-to-cut-data-elements-included-in-a-text-line-tp18533319p18533319.html
> Sent from the R help mailing list archive at Nabble.com.
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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