Skip to content
Prev 279236 / 398506 Next

help in removal of fixed pattern

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 of thing)

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

-Dave
On Fri, 2 Dec 2011, arunkumar1111 wrote: