Returns the number of levels of a factor or a set of factors, currently e.g., for each of the grouping factors of lmer(), glmer(), etc.

ngrps(object, ...)

Arguments

object

an R object, see Details.

...

currently ignored.

Value

The number of levels (of a factor) or vector of number of levels for each “grouping factor” of a

Details

Currently there are methods for objects of class merMod, i.e., the result of lmer() etc, and factor objects.

Examples

ngrps(factor(seq(1,10,2)))
#> [1] 5
ngrps(lmer(Reaction ~ 1|Subject, sleepstudy))
#> Subject 
#>      18 

## A named vector if there's more than one grouping factor :
ngrps(lmer(strength ~ (1|batch/cask), Pastes))
#> cask:batch      batch 
#>         30         10 
## cask:batch      batch
##         30         10

methods(ngrps) # -> "factor" and "merMod"
#> [1] ngrps.default* ngrps.factor*  ngrps.merMod* 
#> see '?methods' for accessing help and source code