Re: [R] Manipulate Data (with regular expressions)

From: oscar Linares <olinares6s_at_yahoo.com>
Date: Tue, 08 Jul 2008 07:28:41 -0700 (PDT)


Check out sedit() in the Hmisc package

Cheers!

> From: Kunzler, Andreas <a.kunzler_at_bzaek.de>
> Subject: [R] Manipulate Data (with regular expressions)
> To: r-help@r-project.org
> Date: Tuesday, July 8, 2008, 7:11 AM
> Dear Everyone,
>
>
>
> I try to automatically manipulate the data of a variable
> (class =
> factor) like
>
>
>
> x
>
> 220
>
> 220a
>
> 221
>
> 221b
>
> B221
>
>
>
> Into two variables (class = numeric) like
>
>
>
> x y
>
> 220 0
>
> 220 1
>
> 221 0
>
> 221 1
>
> 221 1
>
>
>
> y has to carry the information about the class (number or
> string) of the
> former x-Variable.
>
>
>
> I could do it by hand like
>
>
>
> x[x == "220a"] <- 220
>
> y[x == "220a"] <- 1
>
>
>
> but x has way to many expressions.
>
>
>
> So I wondered if I could use a regular expression like OR
> ANY OTHER WAY
>
>
>
> x[x == [0-9]{3}a] <- regular expression
>
> y[x == [0-9]{3}] <- 1
>
>
>
>
>
> Thanks a lot
>
>
>
>
> [[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.



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. Received on Tue 08 Jul 2008 - 15:08:12 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 08 Jul 2008 - 16:32:04 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive