[R] converting to factor

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Tue Apr 22 23:28: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.
> 

Sorry, wrong syntax for what you asked for:


R>
R> cut(c(2.5, 1.6, 3.2), breaks = c(-Inf, 3, Inf))
[1] (-Inf,3] (-Inf,3] (3,Inf]
Levels: (-Inf,3] (3,Inf]
R>



More information about the R-help mailing list