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
Levels number of a factor object
6 messages · Laurent Houdusse, Marc Schwartz, tobias.verbeke@bivv.be +3 more
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
r-help-bounces at stat.math.ethz.ch wrote on 23/01/2004 15:24:21:
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
Is length(levels(groups)) what you were looking for ? HTH, Tobias
groups<-gl(4,10)
> levels(groups)
[1] "1" "2" "3" "4"
> length(levels(groups))
[1] 4
Is this what you want?
spencer graves
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
______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Laurent Houdusse <l.houdusse at cerep.fr> writes:
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
Do you mean just length(levels(groups)) ?
O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Laurent Houdusse schrieb:
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
Simply try: length(levels(groups)) Thomas P.