gsummary.Rd
Provide a summary of the variables in a data frame by groups of rows.
This is most useful with a groupedData
object to examine the
variables by group.
gsummary(object, FUN, omitGroupingFactor, form, level,
groups, invariantsOnly, ...)
an object to be summarized - usually a groupedData
object or a data.frame
.
an optional summary function or a list of summary functions
to be applied to each variable in the frame. The function or
functions are applied only to variables in object
that vary
within the groups defined by groups
. Invariant variables are
always summarized by group using the unique value that they assume
within that group. If FUN
is a single
function it will be applied to each non-invariant variable by group
to produce the summary for that variable. If FUN
is a list of
functions, the names in the list should designate classes of
variables in the frame such as ordered
, factor
, or
numeric
. The indicated function will be applied to any
non-invariant variables of that class. The default functions to be
used are mean
for numeric factors, and Mode
for both
factor
and ordered
. The Mode
function, defined
internally in gsummary
, returns the modal or most popular
value of the variable. It is different from the mode
function
that returns the S-language mode of the variable.
an optional logical value. When TRUE
the grouping factor itself will be omitted from the group-wise
summary but the levels of the grouping factor will continue to be
used as the row names for the data frame that is produced by the
summary. Defaults to FALSE
.
an optional one-sided formula that defines the groups.
When this formula is given, the right-hand side is evaluated in
object
, converted to a factor if necessary, and the unique
levels are used to define the groups. Defaults to
formula(object)
.
an optional positive integer giving the level of grouping to be used in an object with multiple nested grouping levels. Defaults to the highest or innermost level of grouping.
an optional factor that will be used to split the
rows into groups. Defaults to getGroups(object, form, level)
.
an optional logical value. When TRUE
only
those covariates that are invariant within each group will be
summarized. The summary value for the group is always the unique
value taken on by that covariate within the group. The columns in
the summary are of the same class as the corresponding columns in
object
. By definition, the grouping factor itself must be an
invariant. When combined with omitGroupingFactor = TRUE
,
this option can be used to discover is there are invariant covariates
in the data frame. Defaults to FALSE
.
optional additional arguments to the summary functions
that are invoked on the variables by group. Often it is helpful to
specify na.rm = TRUE
.
A data.frame
with one row for each level of the grouping
factor. The number of columns is at most the number of columns in
object
.
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
gsummary(Orthodont) # default summary by Subject
#> distance age Subject Sex
#> M16 23.000 11 M16 Male
#> M05 23.000 11 M05 Male
#> M02 23.375 11 M02 Male
#> M11 23.625 11 M11 Male
#> M07 23.750 11 M07 Male
#> M08 23.875 11 M08 Male
#> M03 24.250 11 M03 Male
#> M12 24.250 11 M12 Male
#> M13 24.250 11 M13 Male
#> M14 24.875 11 M14 Male
#> M09 25.125 11 M09 Male
#> M15 25.875 11 M15 Male
#> M06 26.375 11 M06 Male
#> M04 26.625 11 M04 Male
#> M01 27.750 11 M01 Male
#> M10 29.500 11 M10 Male
#> F10 18.500 11 F10 Female
#> F09 21.125 11 F09 Female
#> F06 21.125 11 F06 Female
#> F01 21.375 11 F01 Female
#> F05 22.625 11 F05 Female
#> F07 23.000 11 F07 Female
#> F02 23.000 11 F02 Female
#> F08 23.375 11 F08 Female
#> F03 23.750 11 F03 Female
#> F04 24.875 11 F04 Female
#> F11 26.375 11 F11 Female
## gsummary with invariantsOnly = TRUE and omitGroupingFactor = TRUE
## determines whether there are covariates like Sex that are invariant
## within the repeated observations on the same Subject.
gsummary(Orthodont, invariantsOnly = TRUE, omitGroupingFactor = TRUE)
#> Sex
#> M16 Male
#> M05 Male
#> M02 Male
#> M11 Male
#> M07 Male
#> M08 Male
#> M03 Male
#> M12 Male
#> M13 Male
#> M14 Male
#> M09 Male
#> M15 Male
#> M06 Male
#> M04 Male
#> M01 Male
#> M10 Male
#> F10 Female
#> F09 Female
#> F06 Female
#> F01 Female
#> F05 Female
#> F07 Female
#> F02 Female
#> F08 Female
#> F03 Female
#> F04 Female
#> F11 Female