Message-ID: <1074868403.5657.26.camel@localhost.localdomain>
Date: 2004-01-23T14:33:23Z
From: Marc Schwartz
Subject: Levels number of a factor object
In-Reply-To: <BA420EFAAC96D311A7A0006097D37BDB045159FA@EOLE>
On Fri, 2004-01-23 at 08:24, Laurent Houdusse wrote:
> 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
Use nlevels() for the number of levels and levels() to get the actual
level values:
> groups <- gl(4, 10)
> groups
[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
> nlevels(groups)
[1] 4
> levels(groups)
[1] "1" "2" "3" "4"
See ?nlevels and ?levels for more information.
HTH,
Marc Schwartz