This function calculates the mean and standard deviation of a numerical variable for each level of a grouping variable and performs a one-way ANOVA test. The output is a formatted table that includes group-wise means, standard deviations, and a p-value.

compare_numerical(
  dat,
  col_var,
  row_var,
  varname = "",
  colname = "Variables",
  total = FALSE
)

Arguments

dat

A data frame containing the variables.

col_var

The grouping variable (factor or categorical).

row_var

The numerical variable for which mean and standard deviation are computed.

varname

A character string to label the row in the output table.

colname

A character string for naming the output table column.

total

Logical; if TRUE, includes overall mean and SD.

Value

A data frame containing group-wise means and standard deviations of row_var for each level of col_var, along with the p-value from the one-way ANOVA test.

Details

The function computes the mean and standard deviation for row_var within each group defined by col_var, as well as overall. It performs a one-way ANOVA test to assess differences in means between groups. Results are presented in a table that includes the p-value.

Examples

compare_numerical(mtcars, 'cyl', 'mpg', varname = 'Miles per Gallon')
#>                     Variables            4            6            8 p-value
#> 1 Miles per Gallon, mean (SD) 26.66 (4.51) 19.74 (1.45) 15.10 (2.56)  <0.001