[Stable]
This function generates a table of descriptive statistics (mainly using psych::describe()) and or a correlation table. User can export this to a csv file (optionally, using the file_path argument). Users can open the csv file with MS Excel then copy and paste the table into MS Word table.

descriptive_table(
  data,
  cols,
  ...,
  digits = 3,
  descriptive_indicator = c("mean", "sd", "cor"),
  file_path = NULL,
  streamline = FALSE,
  quite = FALSE,
  show_p = FALSE,
  return_result = FALSE
)

Arguments

data

data.frame

cols

column(s) need to be included in the table. Support dplyr::select() syntax.

...

additional arguments passed to cor_test. See ?cor_test.

digits

number of digit for the descriptive table

descriptive_indicator

Default is mean, sd, cor. Options are missing (missing value count), non_missing (non-missing value count), cor (correlation table), n, mean, sd, median, trimmed (trimmed mean), median, mad (median absolute deviation from the median), min, max, range, skew, kurtosis, se (standard error)

file_path

file path for export. The function will implicitly pass this argument to the write.csv(file = file_path)

streamline

print streamlined output

quite

suppress printing output

show_p

Default is FALSE. If TRUE, show the p-value in parenthesis for correlations.

return_result

If it is set to TRUE, it will return the data frame of the descriptive table

Value

a data.frame of the descriptive table

Examples

descriptive_table(iris, cols = where(is.numeric)) # all numeric columns
#> Model Summary
#> Model Type = Correlation
#> Model Method = pearson
#> Adjustment Method = none
#> 
#> ───────────────────────────────────────────────────────
#>            Var  Sepal.Length  Sepal.Width  Petal.Length
#> ───────────────────────────────────────────────────────
#>   Sepal.Length                                         
#>    Sepal.Width    -0.118                               
#>   Petal.Length     0.872 ***   -0.428 ***              
#>    Petal.Width     0.818 ***   -0.366 ***     0.963 ***
#> ───────────────────────────────────────────────────────
#> Note: * p < 0.05, ** p < 0.01, *** p < 0.001
#> 
#> Model Summary
#> Model Type = Descriptive Statistics
#> 
#> ─────────────────────────────────────────────────────────────────────
#>            Var   mean     sd  Sepal.Length  Sepal.Width  Petal.Length
#> ─────────────────────────────────────────────────────────────────────
#>   Sepal.Length  5.843  0.828                                         
#>    Sepal.Width  3.057  0.436    -0.118                               
#>   Petal.Length  3.758  1.765     0.872 ***   -0.428 ***              
#>    Petal.Width  1.199  0.762     0.818 ***   -0.366 ***     0.963 ***
#> ─────────────────────────────────────────────────────────────────────
#> 

descriptive_table(iris,
  cols = where(is.numeric),
  # get missing count, non-missing count, and mean & sd & correlation table
  descriptive_indicator = c("missing", "non_missing", "mean", "sd", "cor")
)
#> Model Summary
#> Model Type = Correlation
#> Model Method = pearson
#> Adjustment Method = none
#> 
#> ───────────────────────────────────────────────────────
#>            Var  Sepal.Length  Sepal.Width  Petal.Length
#> ───────────────────────────────────────────────────────
#>   Sepal.Length                                         
#>    Sepal.Width    -0.118                               
#>   Petal.Length     0.872 ***   -0.428 ***              
#>    Petal.Width     0.818 ***   -0.366 ***     0.963 ***
#> ───────────────────────────────────────────────────────
#> Note: * p < 0.05, ** p < 0.01, *** p < 0.001
#> 
#> Model Summary
#> Model Type = Descriptive Statistics
#> 
#> ───────────────────────────────────────────────────────────────────────────────────────────────
#>            Var  missing_n  non_missing_n   mean     sd  Sepal.Length  Sepal.Width  Petal.Length
#> ───────────────────────────────────────────────────────────────────────────────────────────────
#>   Sepal.Length          0            150  5.843  0.828                                         
#>    Sepal.Width          0            150  3.057  0.436    -0.118                               
#>   Petal.Length          0            150  3.758  1.765     0.872 ***   -0.428 ***              
#>    Petal.Width          0            150  1.199  0.762     0.818 ***   -0.366 ***     0.963 ***
#> ───────────────────────────────────────────────────────────────────────────────────────────────
#> You can drag and resize the R console to view the entire table
#>