[R] regular expression for selection
Rainer Schuermann
rainer.schuermann at gmx.net
Mon Nov 14 10:50:09 CET 2011
Does
library( stringr )
str_extract( mena, "m5[0-9]" )
achieve what you are looking for?
Rgds,
Rainer
On Monday 14 November 2011 10:22:09 Petr PIKAL wrote:
> Hi
>
> > On 11/14/2011 07:45 PM, Petr PIKAL wrote:
> > > Dear all
> > >
> > > I am again (as usual) lost in regular expression use for
> > > selection.
>
> Here
>
> > > are my data:
> > >> dput(mena)
> > >
> > > c("138516_10g_50ml_50c_250utes1_m53.00-_s1.imp",
> > > "138516_10g_50ml_50c_250utes1_m54.00_s1.imp",
> > > "138516_10g_50ml_50c_250utes1_m55.00_s1.imp",
> > > "138516_10g_50ml_50c_250utes1_m56.00_s1.imp",
> > > "138516_10g_50ml_50c_250utes1_m57.00_s1.imp",
> > > "138516_10g_50ml_50c_250utes1_m58.00_s1.imp",
> > > "138516_10g_50ml_50c_250utes1_m59.00_s1.imp")
> > >
> > > I want to select only values "m" foolowed by numbers from 53 to
> > > 59.
> > >
> > > I used
> > >
> > > sub("m5.", "", mena)
> > >
> > > which correctly selects those m53 - m59 values but, in contrary
> > > to my expectation, it replaced the selected values with
> > > specified
> replacement -
>
> > > in that case empty string.
> > >
> > > What I shall use if I want to get rid of all but m53-m59 from
> > > those
> > > strings?
> >
> > Hi Petr,
> > How about:
> >
> > grep("m5",mena)
>
> It gives numeric values which tells me that there is a match in each
> string, but as a result I need only
>
> m53-m59 substrings.
>
> Regards
> Petr
>
> > Jim
>
> ______________________________________________
> 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