tidy_correlation: Generate tidy correlations

View source: R/tidy-stats.R

tidy_correlationR Documentation

Generate tidy correlations

Description

This function respects groupings from dplyr::group_by(). When the dataframe contains grouped data, the correlations are computed within each subgroup of data.

Usage

tidy_correlation(data, ..., type = c("pearson", "spearman"))

Arguments

data

a dataframe

...

columns to select, using dplyr::select() semantics.

type

type of correlation, either "pearson" (the default) or "spearman".

Value

a long dataframe (a tibble) with correlations calculated for each pair of columns.

Examples

tidy_correlation(ChickWeight, -Chick, -Diet)

tidy_correlation(ChickWeight, weight, Time)

ChickWeight %>%
  dplyr::group_by(Diet) %>%
  tidy_correlation(weight, Time)

tjmahr/tjmisc documentation built on Feb. 8, 2023, 12:21 p.m.