ngrp {quest} | R Documentation |
Number of Groups in Data
Description
ngrp
computes the number of groups in data given one or more grouping
variables. This is simply a combination of unique.data.frame
+
nrow
.
Usage
ngrp(data, grp.nm)
Arguments
data |
data.frame of data. |
grp.nm |
character vector of colnames from |
Value
integer vector of length 1 specifying the number of groups.
See Also
nrow_ml
ncases_ml
nrow_by
ncases_by
Examples
# one grouping variable
Orthodont2 <- as.data.frame(nlme::Orthodont)
ngrp(Orthodont2, grp.nm = "Subject")
length(unique(Orthodont2$"Subject"))
# two grouping variable
co2 <- as.data.frame(CO2)
ngrp(co2, grp.nm = c("Plant"))
grp_nm <- c("Type","Treatment")
ngrp(co2, grp.nm = grp_nm)
unique.data.frame(co2[grp_nm])
#TODO: how does it handle factor levels with no cases?
[Package quest version 0.2.0 Index]