This function returns the correlations between different variables.

get_var_corr(
  df,
  comparison_var = NULL,
  other_vars = NULL,
  method = "pearson",
  drop_columns = c("factor", "character"),
  ...
)

Arguments

df

The data set for which correlations are required

comparison_var

The variable to compare to

other_vars

variables for which correlation with comparison_var is required. If not supplied, all variables will be used.

method

The method used to perform the correlation test as defined in 'cor.test'. Defaults to pearson.

drop_columns

A character vector specifying column classes to drop. Defaults to c("factor","character")

...

Other arguments to 'cor.test' see ?cor.test for details

Value

A data.frame object containing correlations between comparison_var and each of other_vars

Examples

# Get correlations between all variables
get_var_corr(mtcars,"mpg")
#>    comparison_var other_var      p.value correlation    lower_ci   upper_ci
#> 1             mpg       cyl 6.112687e-10  -0.8521620 -0.92576936 -0.7163171
#> 2             mpg      disp 9.380327e-10  -0.8475514 -0.92335937 -0.7081376
#> 3             mpg        hp 1.787835e-07  -0.7761684 -0.88526861 -0.5860994
#> 4             mpg      drat 1.776240e-05   0.6811719  0.43604838  0.8322010
#> 5             mpg        wt 1.293959e-10  -0.8676594 -0.93382641 -0.7440872
#> 6             mpg      qsec 1.708199e-02   0.4186840  0.08195487  0.6696186
#> 7             mpg        vs 3.415937e-05   0.6640389  0.41036301  0.8223262
#> 8             mpg        am 2.850207e-04   0.5998324  0.31755830  0.7844520
#> 9             mpg      gear 5.400948e-03   0.4802848  0.15806177  0.7100628
#> 10            mpg      carb 1.084446e-03  -0.5509251 -0.75464796 -0.2503183
# Use only a few variables
get_var_corr(mtcars,"mpg", other_vars = c("disp","drat"), method = "kendall",exact=FALSE)
#>   comparison_var other_var      p.value correlation
#> 1            mpg      disp 1.006950e-09  -0.7681311
#> 2            mpg      drat 2.381533e-04   0.4645488