correlate | R Documentation |
An implementation of stats::cor(), which returns a correlation data frame rather than a matrix. See details below. Additional adjustment include the use of pairwise deletion by default.
correlate( x, y = NULL, use = "pairwise.complete.obs", method = "pearson", diagonal = NA, quiet = FALSE )
x |
a numeric vector, matrix or data frame. |
y |
|
use |
an optional character string giving a
method for computing covariances in the presence
of missing values. This must be (an abbreviation of) one of the strings
|
method |
a character string indicating which correlation
coefficient (or covariance) is to be computed. One of
|
diagonal |
Value (typically numeric or NA) to set the diagonal to |
quiet |
Set as TRUE to suppress message about |
This function returns a correlation matrix as a correlation data frame in the following format:
A tibble (see tibble
)
An additional class, "cor_df"
A "term" column
Standardized variances (the matrix diagonal) set to missing values by
default (NA
) so they can be ignored in calculations.
The use
argument and its possible values are inherited from stats::cor()
:
"everything": NAs will propagate conceptually, i.e. a resulting value will be NA whenever one of its contributing observations is NA
"all.obs": the presence of missing observations will produce an error
"complete.obs": correlations will be computed from complete observations, with an error being raised if there are no complete cases.
"na.or.complete": correlations will be computed from complete observations, returning an NA if there are no complete cases.
"pairwise.complete.obs": the correlation between each pair of variables is computed using all complete pairs of those particular variables.
As of version 0.4.3, the first column of a cor_df
object is named "term".
In previous versions this first column was named "rowname".
There is a ggplot2::autoplot()
method for quickly visualizing the
correlation matrix, for more information see autoplot.cor_df()
.
A correlation data frame cor_df
## Not run: correlate(iris) ## End(Not run) correlate(iris[-5]) correlate(mtcars) ## Not run: # Also supports DB backend and collects results into memory library(sparklyr) sc <- spark_connect(master = "local") mtcars_tbl <- copy_to(sc, mtcars) mtcars_tbl %>% correlate(use = "pairwise.complete.obs", method = "spearman") spark_disconnect(sc) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.