[R] factor based on pattern match ?
Liaw, Andy
andy_liaw at merck.com
Thu Mar 25 23:16:34 CET 2004
Is the following sort of what you want?
> 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,...{{dropped}}
More information about the R-help
mailing list