Skip to content

Levels number of a factor object

6 messages · Laurent Houdusse, Marc Schwartz, tobias.verbeke@bivv.be +3 more

#
Hi all!

    How to retrieve the levels number of a factor object?
    See this code:
    groups<-gl(4,10)
    I want to retrieve the number of levels (4) of my object "groups"
    I tried groups.levels but this don't work

    Thanks


Laurent Houdusse 
Analyste Programmeur
#
On Fri, 2004-01-23 at 08:24, Laurent Houdusse wrote:
Use nlevels() for the number of levels and levels() to get the actual
level values:
[1] 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4
[35] 4 4 4 4 4 4
Levels: 1 2 3 4
[1] 4
[1] "1" "2" "3" "4"

See ?nlevels and ?levels for more information.

HTH,

Marc Schwartz
#
r-help-bounces at stat.math.ethz.ch wrote on 23/01/2004 15:24:21:
Is

length(levels(groups))


what you were looking for ?


HTH,

Tobias
#
> levels(groups)
[1] "1" "2" "3" "4"
 > length(levels(groups))
[1] 4

      Is this what you want? 
      spencer graves
Laurent Houdusse wrote:

            
#
Laurent Houdusse <l.houdusse at cerep.fr> writes:
Do you mean just

length(levels(groups))

?
#
Laurent Houdusse schrieb:
Simply try:

length(levels(groups))

Thomas P.