Description Usage Arguments Details Value See Also Examples
Return the correlations between the columns of a matrix or data frame as
a "cor_list"
object.
1 |
x |
a numeric matrix or data frame. |
y |
NULL (default) or a matrix or data frame with compatible dimensions to x. The default is equivalent to y = x (but more efficient). |
use |
an optional character string giving a method for handling missing
values. This must be (an abbreviation of) one of the strings "everything",
"all.obs", "complete.obs", "na.or.complete", or "pairwise.complete.obs"
(default). See |
method |
a character string indicating which correlation coefficient is to be computed. One of "pearson" (default), "kendall", or "spearman": can be abbreviated. |
The cor
function from the R stats package returns
bivariate correlations as a matrix of values, which can be difficult to parse
when there are many correlations. cor_list
converts the correlation
matrix into a list of all row-column pairs, removing the diagonal entries,
and stores the type of correlation coefficient (Pearson's r, Kendall's
tau, or Spearman's rho) as an attribute in a cor_list
object with specialized print
and summarize
methods. The
print
method automatically outputs unique bivariate relationships,
sorted from strongest to weakest. The summarise.cor_list
method
enables the use of select_helpers
expressions to return
specific bivariate relationships that you want to look at.
cor_list
differs from R's native cor
in the
following ways:
x
(and, if given, y
) must be a matrix or data frame
with named columns; unnamed vectors are not allowed. (You can still
pass data for a single variable as x
or y
, but it must
be in the form of a one-column matrix or data frame rather than a
numeric vector.)
The default argument for use
is pairwise-complete observations
instead of "everything".
The cor_list
object stores the type of correlation
coefficient as an attribute.
The cor_list
object has special summarize methods for
selectively viewing relationships of interest. See
summarize.cor_list
.
A cor_list
object with the following three vectors:
x
variables that form the rows of the correlation matrix
y
variables that form the columns of the correlation matrix
coef
the correlation coefficient between corresponding
elements of x
and y
and the attribute "coef" indicating the statistic that is being returned (Pearson's r, Kendall's tau, or Spearman's rho).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | # Create a correlation list for the numeric variables from the iris data set
iris_cors <- cor_list(iris[,-5])
# Print returns all unique bivariate relationships sorted by strength
iris_cors
# Look at all correlations with Sepal.Length
summarize(iris_cors, x = Sepal.Length)
# Look at all correlations between sepal measurements and petal measurements
summarize(iris_cors, x = starts_with("Sepal"), y = starts_with("Petal"))
# Look at all correlations with Sepal.Length, excluding Sepal.Width
summarize(iris_cors, x = Sepal.Length, y = -Sepal.Width)
# Look at all correlations in their original order
summarize(iris_cors, sort = FALSE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.