Learn R Programming

correlation (version 0.8.6)

cormatrix_to_excel: Easy export of correlation matrix to Excel

Description

Easily output a correlation matrix and export it to Microsoft Excel, with the first row and column frozen, and correlation coefficients colour-coded based on effect size (0.0-0.2: small (no colour); 0.2-0.4: medium (pink/light blue); 0.4-1.0: large (red/dark blue)), following Cohen's suggestions for small (.10), medium (.30), and large (.50) correlation sizes.

Usage

cormatrix_to_excel(data, filename, overwrite = TRUE, print.mat = TRUE, ...)

Value

A Microsoft Excel document, containing the colour-coded correlation matrix with significance stars, on the first sheet, and the colour-coded p-values on the second sheet.

Arguments

data

The data frame

filename

Desired filename (path can be added before hand but no need to specify extension).

overwrite

Whether to allow overwriting previous file.

print.mat

Logical, whether to also print the correlation matrix to console.

...

Parameters to be passed to correlation()

Author

Adapted from @JanMarvin (JanMarvin/openxlsx2#286) and the original rempsyc::cormatrix_excel.

Examples

Run this code
if (FALSE) { # requireNamespace("openxlsx2", quietly = TRUE)
# \dontshow{
.old_wd <- setwd(tempdir())
# }
# Basic example
suppressWarnings(cormatrix_to_excel(mtcars,
  select = c("mpg", "cyl", "disp", "hp", "carb"), filename = "cormatrix1"
))
suppressWarnings(cormatrix_to_excel(iris,
  p_adjust = "none",
  filename = "cormatrix2"
))
suppressWarnings(cormatrix_to_excel(airquality,
  method = "spearman",
  filename = "cormatrix3"
))
# \dontshow{
setwd(.old_wd)
# }
}

Run the code above in your browser using DataLab