[R] factor based on pattern match ?
Oleg Bartunov
oleg at sai.msu.su
Thu Mar 25 23:51:54 CET 2004
On Thu, 25 Mar 2004, Liaw, Andy wrote:
> Is the following sort of what you want?
thanks for example, but I need something more :)
In real situation, I'd like to use perl like patterns (like in grep),
or just implicitly specify levels, for example: level F is ("f.*", "mmm")
>
> > y = factor(c("ff","f","m","mm","fm","mf","ffm","mmf","mmm","fff"))
> > levels(y) <- substring(levels(y), 1, 1)
> > y
> [1] f f m m f m f m m f
> Levels: f m
>
> Andy
>
> > From: Oleg Bartunov
> >
> > Hello,
> >
> > is't possible to specify pattern in levels ?
> >
> > > y=c("ff","f","m","mm","fm","mf","ffm","mmf","mmm","fff");
> > > factor(y)
> > [1] ff f m mm fm mf ffm mmf mmm fff
> > Levels: f ff fff ffm fm m mf mm mmf mmm
> >
> > I want to specify levels using regexp ("f.*","m.*") or use some
> > another method. So, I could have 2 levels, say, F and M, where
> > F means everything beginning from 'f' and M - from 'm'.
> >
> > Something like cut() for numerical data.
> >
> > Regards,
> > Oleg
> > _____________________________________________________________
> > Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
> > Sternberg Astronomical Institute, Moscow University (Russia)
> > Internet: oleg at sai.msu.su, http://www.sai.msu.su/~megera/
> > phone: +007(095)939-16-83, +007(095)939-23-83
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> > http://www.R-project.org/posting-guide.html
> >
> >
>
>
> ------------------------------------------------------------------------------
> Notice: This e-mail message, together with any attachments, contains
> information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New
> Jersey, USA 08889), and/or its affiliates (which may be known outside the
> United States as Merck Frosst, Merck Sharp & Dohme or MSD and in Japan as
> Banyu) that may be confidential, proprietary copyrighted and/or legally
> privileged. It is intended solely for the use of the individual or entity
> named on this message. If you are not the intended recipient, and have
> received this message in error, please notify us immediately by reply e-mail
> and then delete it from your system.
> ------------------------------------------------------------------------------
>
Regards,
Oleg
_____________________________________________________________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg at sai.msu.su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83
More information about the R-help
mailing list