A great function for extracting pattern matches is 'm()'
library(caroline)
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
You can use gsub() to replace parts of strings.
Sarah
On Saturday, December 3, 2011, arunkumar 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 Outp
2 matches
Mail list logo