[R] help in removal of fixed pattern

D. Schruth dschruth at u.washington.edu
Sun Dec 4 01:39:35 CET 2011

A great function for extracting pattern matches is 'm()'

vect <- m('([xX][0-9])',df$Input)
toupper(vect)  #in case you really want all upper case x's

It does the hard work of using 'sub' to remove the non-matching parts 
(sub, grep, regexpr, etc aren't very good for this sort of thing)

It also can return a data.frame if you have multiple patterns you wish to 
match in each string vector element.


On Fri, 2 Dec 2011, arunkumar1111 wrote:

> Hi
> I have column name as given below
> If the variable is in log(X1 + 1) pattern it should be removed and i need
> only X1
> Input
> log(x1 + 1)
> x2
> log(X3 +1)
> Expected Output X1 X2 X3
> Please help me
> --
> View this message in context: http://r.789695.n4.nabble.com/help-in-removal-of-fixed-pattern-tp4152524p4152524.html
> Sent from the R help mailing list archive at Nabble.com.
> ______________________________________________
> 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