# GroupMean: Calculation of Groupwise Descriptive Statistics for Matrices In miceadds: Some Additional Multiple Imputation Functions, Especially for 'mice'

## Description

Calculates some groupwise descriptive statistics

## Usage

 ```1 2 3 4 5``` ```GroupMean(data, group, weights=NULL, extend=FALSE) GroupSum(data, group, weights=NULL, extend=FALSE) GroupSD(data, group, weights=NULL, extend=FALSE) ```

## Arguments

 `data` A numeric data frame `group` A vector of group identifiers `weights` An optional vector of sample weights `extend` Optional logical indicating whether the group means (or sums) should be extended to the original dimensions of the dataset.

## Value

A data frame with groupwise calculated statistics

## Author(s)

Alexander Robitzsch

`mitml::clusterMeans`
`base::rowsum`, `stats::aggregate`, `stats::ave`
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29``` ```############################################################################# # EXAMPLE 1: Group means and SDs data.ma02 ############################################################################# data( data.ma02 ) dat <- data.ma02[[1]] # select first dataset #--- group means for read and math GroupMean( dat[ , c("read","math") ] , group=dat\$idschool ) # using rowsum a1 <- base::rowsum( dat[ , c("read","math") ] , dat\$idschool ) a2 <- base::rowsum( 1+0*dat[ , c("read","math") ] , dat\$idschool ) (a1/a2)[1:10,] # using aggregate stats::aggregate( dat[ , c("read","math") ] , list(dat\$idschool) , mean )[1:10,] #--- extend group means to original dataset GroupMean( dat[ , c("read","math") ] , group=dat\$idschool , extend =TRUE ) # using ave stats::ave( dat[ , "read" ] , dat\$idschool ) stats::ave( dat[ , "read" ] , dat\$idschool , FUN = mean ) ## Not run: #--- group standard deviations GroupSD( dat[ , c("read","math") ] , group=dat\$idschool)[1:10,] # using aggregate stats::aggregate( dat[ , c("read","math") ] , list(dat\$idschool) , sd )[1:10,] ## End(Not run) ```