stretch
is a specified implementation of tidyr::gather() to be applied
to a correlation data frame. It will gather the columns into a long-format
data frame. The term column is handled automatically.
stretch(x, na.rm = FALSE, remove.dups = FALSE)
x | cor_df. See |
---|---|
na.rm | Boolean. Whether rows with an NA correlation (originally the matrix diagonal) should be dropped? Will automatically be set to TRUE if mirror is FALSE. |
remove.dups | Removes duplicate entries, without removing all NAs |
tbl with three columns (x and y variables, and their correlation)
#> #>#>stretch(x) # Convert all to long format#> # A tibble: 121 x 3 #> x y r #> <chr> <chr> <dbl> #> 1 mpg mpg NA #> 2 mpg cyl -0.852 #> 3 mpg disp -0.848 #> 4 mpg hp -0.776 #> 5 mpg drat 0.681 #> 6 mpg wt -0.868 #> 7 mpg qsec 0.419 #> 8 mpg vs 0.664 #> 9 mpg am 0.600 #> 10 mpg gear 0.480 #> # … with 111 more rowsstretch(x, na.rm = FALSE) # omit NAs (diagonal in this case)#> # A tibble: 121 x 3 #> x y r #> <chr> <chr> <dbl> #> 1 mpg mpg NA #> 2 mpg cyl -0.852 #> 3 mpg disp -0.848 #> 4 mpg hp -0.776 #> 5 mpg drat 0.681 #> 6 mpg wt -0.868 #> 7 mpg qsec 0.419 #> 8 mpg vs 0.664 #> 9 mpg am 0.600 #> 10 mpg gear 0.480 #> # … with 111 more rowsx <- shave(x) # use shave to set upper triangle to NA and then... stretch(x, na.rm = FALSE) # omit all NAs, therefore keeping each#> # A tibble: 121 x 3 #> x y r #> <chr> <chr> <dbl> #> 1 mpg mpg NA #> 2 mpg cyl -0.852 #> 3 mpg disp -0.848 #> 4 mpg hp -0.776 #> 5 mpg drat 0.681 #> 6 mpg wt -0.868 #> 7 mpg qsec 0.419 #> 8 mpg vs 0.664 #> 9 mpg am 0.600 #> 10 mpg gear 0.480 #> # … with 111 more rows# correlation only once.