rearrange: Re-arrange a correlation data frame

Description Usage Arguments Value Examples

View source: R/internal.R

Description

Re-arrange a correlation data frame to group highly correlated variables closer together.

Usage

1
rearrange(x, method = "PC", absolute = TRUE)

Arguments

x

cor_df. See correlate.

method

String specifying the arrangement (clustering) method. Clustering is achieved via seriate, which can be consulted for a complete list of clustering methods. Default = "PCA".

absolute

Boolean whether absolute values for the correlations should be used for clustering.

Value

cor_df. See correlate.

Examples

1
2
3
4
5
x <- correlate(mtcars)

rearrange(x) # Default settings
rearrange(x, method = "HC")  # Different seriation method
rearrange(x, absolute = FALSE)  # Not using absolute values for arranging

Example output

Loading required package: dplyr

Attaching package: 'dplyr'

The following objects are masked from 'package:stats':

    filter, lag

The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union

# A tibble: 11 x 12
   rowname          am       gear        drat         wt       disp        mpg
     <chr>       <dbl>      <dbl>       <dbl>      <dbl>      <dbl>      <dbl>
 1      am          NA  0.7940588  0.71271113 -0.6924953 -0.5912270  0.5998324
 2    gear  0.79405876         NA  0.69961013 -0.5832870 -0.5555692  0.4802848
 3    drat  0.71271113  0.6996101          NA -0.7124406 -0.7102139  0.6811719
 4      wt -0.69249526 -0.5832870 -0.71244065         NA  0.8879799 -0.8676594
 5    disp -0.59122704 -0.5555692 -0.71021393  0.8879799         NA -0.8475514
 6     mpg  0.59983243  0.4802848  0.68117191 -0.8676594 -0.8475514         NA
 7     cyl -0.52260705 -0.4926866 -0.69993811  0.7824958  0.9020329 -0.8521620
 8      vs  0.16834512  0.2060233  0.44027846 -0.5549157 -0.7104159  0.6640389
 9      hp -0.24320426 -0.1257043 -0.44875912  0.6587479  0.7909486 -0.7761684
10    carb  0.05753435  0.2740728 -0.09078980  0.4276059  0.3949769 -0.5509251
11    qsec -0.22986086 -0.2126822  0.09120476 -0.1747159 -0.4336979  0.4186840
# ... with 5 more variables: cyl <dbl>, vs <dbl>, hp <dbl>, carb <dbl>,
#   qsec <dbl>
# A tibble: 11 x 12
   rowname         hp         vs        qsec        carb         wt        cyl
     <chr>      <dbl>      <dbl>       <dbl>       <dbl>      <dbl>      <dbl>
 1      hp         NA -0.7230967 -0.70822339  0.74981247  0.6587479  0.8324475
 2      vs -0.7230967         NA  0.74453544 -0.56960714 -0.5549157 -0.8108118
 3    qsec -0.7082234  0.7445354          NA -0.65624923 -0.1747159 -0.5912421
 4    carb  0.7498125 -0.5696071 -0.65624923          NA  0.4276059  0.5269883
 5      wt  0.6587479 -0.5549157 -0.17471588  0.42760594         NA  0.7824958
 6     cyl  0.8324475 -0.8108118 -0.59124207  0.52698829  0.7824958         NA
 7     mpg -0.7761684  0.6640389  0.41868403 -0.55092507 -0.8676594 -0.8521620
 8    disp  0.7909486 -0.7104159 -0.43369788  0.39497686  0.8879799  0.9020329
 9    drat -0.4487591  0.4402785  0.09120476 -0.09078980 -0.7124406 -0.6999381
10      am -0.2432043  0.1683451 -0.22986086  0.05753435 -0.6924953 -0.5226070
11    gear -0.1257043  0.2060233 -0.21268223  0.27407284 -0.5832870 -0.4926866
# ... with 5 more variables: mpg <dbl>, disp <dbl>, drat <dbl>, am <dbl>,
#   gear <dbl>
# A tibble: 11 x 12
   rowname        mpg         vs        drat          am       gear        qsec
     <chr>      <dbl>      <dbl>       <dbl>       <dbl>      <dbl>       <dbl>
 1     mpg         NA  0.6640389  0.68117191  0.59983243  0.4802848  0.41868403
 2      vs  0.6640389         NA  0.44027846  0.16834512  0.2060233  0.74453544
 3    drat  0.6811719  0.4402785          NA  0.71271113  0.6996101  0.09120476
 4      am  0.5998324  0.1683451  0.71271113          NA  0.7940588 -0.22986086
 5    gear  0.4802848  0.2060233  0.69961013  0.79405876         NA -0.21268223
 6    qsec  0.4186840  0.7445354  0.09120476 -0.22986086 -0.2126822          NA
 7    carb -0.5509251 -0.5696071 -0.09078980  0.05753435  0.2740728 -0.65624923
 8      hp -0.7761684 -0.7230967 -0.44875912 -0.24320426 -0.1257043 -0.70822339
 9      wt -0.8676594 -0.5549157 -0.71244065 -0.69249526 -0.5832870 -0.17471588
10    disp -0.8475514 -0.7104159 -0.71021393 -0.59122704 -0.5555692 -0.43369788
11     cyl -0.8521620 -0.8108118 -0.69993811 -0.52260705 -0.4926866 -0.59124207
# ... with 5 more variables: carb <dbl>, hp <dbl>, wt <dbl>, disp <dbl>,
#   cyl <dbl>

corrr documentation built on May 29, 2017, 3:44 p.m.