[R] Question about creating unique factor labels with the factor function

From: Gregory Gentlemen <gregory_gentlemen_at_yahoo.ca>
Date: Wed 20 Jul 2005 - 05:11:42 EST


Hi guys,  

I ran into a problem of not being able to create unique labels when creating a factor. Consider an example below:  

 hb <- factor(c(1,1,1,2,2,2,3,3,3), levels=c(1,2,3),labels=c(1,1,2))
> hb

[1] 1 1 1 1 1 1 2 2 2
Levels: 1 1 2
> unique(hb)

[1] 1 1 2
Levels: 1 1 2  

How come there are three unique levels, I thought this would only create one unique level?

> unique(as.ordered(hb))

[1] 1 2
Levels: 1 < 1 < 2  

Is as.ordered the only solution?  

Thanks in advance,
Greg  


        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Jul 20 05:16:51 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:50 EST