[R] converting to factor
Sundar Dorai-Raj
sundar.dorai-raj at pdf.com
Tue Apr 22 23:22:50 CEST 2003
R. Sean Bowman wrote:
> hello,
>
> I have a list of numbers that I want to convert into factors representing
> ranges of values. For example, if I have
>
> c(2.5, 1.6, 3.2)
>
> I might want a list of factors like
>
> c("<3", "<3", ">3")
>
> I think I can do this by writing a function and using apply, as.matrix,
> &c., but I'm looking for a nicer way. Any help is greatly appreciated.
>
See ?cut.
R> cut(c(2.5, 1.6, 3.2), 3)
[1] (2.13,2.67] (1.6,2.13] (2.67,3.2]
Levels: (1.6,2.13] (2.13,2.67] (2.67,3.2]
More information about the R-help
mailing list