Skip to contents

Calculates sums for groups.

Usage

groupwiseSum(
  formula = NULL,
  data = NULL,
  var = NULL,
  group = NULL,
  digits = NULL,
  ...
)

Arguments

formula

A formula indicating the measurement variable and the grouping variables. e.g. y ~ x1 + x2.

data

The data frame to use.

var

The measurement variable to use. The name is in double quotes.

group

The grouping variable to use. The name is in double quotes. Multiple names are listed as a vector. (See example.)

digits

The number of significant figures to use in output. The default is NULL, which results in no rounding of values.

...

Other arguments passed to the sum function

Value

A data frame of statistics by group.

Details

The input should include either formula and data; or data, var, and group. (See examples).

Note

The parsing of the formula is simplistic. The first variable on the left side is used as the measurement variable. The variables on the right side are used for the grouping variables.

Beginning in version 2.0, there is no rounding of results by default. Rounding results can cause confusion if the user is expecting exact sums.

Author

Salvatore Mangiafico, mangiafico@njaes.rutgers.edu

Examples

### Example with formula notation
data(AndersonBias)
groupwiseSum(Count ~ Result + Gender,
             data        = AndersonBias)
#>   Result Gender n Sum
#> 1   Pass Female 4  44
#> 2   Pass   Male 4  49
#> 3   Fail Female 4  24
#> 4   Fail   Male 4  64
                
### Example with variable notation
data(AndersonBias)
groupwiseSum(data        = AndersonBias,
             var         = "Count",
             group       = c("Result", "Gender"))
#>   Result Gender n Sum
#> 1   Pass Female 4  44
#> 2   Pass   Male 4  49
#> 3   Fail Female 4  24
#> 4   Fail   Male 4  64