corr

Computes the pearson correlation between all suitable columns in this DataFrame, including nested columns at any depth.

The result is a square correlation matrix represented by a DataFrame, where both rows and columns correspond to the original columns, and each cell contains the Pearson correlation coefficient between the respective pair of columns.

The function is available for numeric- and Boolean columns. Boolean values are converted into 1 for true and 0 for false. All other columns are ignored.

For more information, see: See corr on the documentation website.

Return

A square correlation matrix as a DataFrame, where both rows and columns correspond to the original columns.


fun <T, C> DataFrame<T>.corr(columns: ColumnsSelector<T, C>): Corr<T, C>

Calculates the Pearson pairwise correlation between values in the specified columns.

This function does not compute the correlation immediately. Instead, it defines the primary set of columns and returns a Corr instance that allows configuring how the correlation should be computed.

The function is available for numeric- and Boolean columns. Boolean values are converted into 1 for true and 0 for false. All other columns are ignored. If a ColumnGroup instance is passed as the target column for correlation, it will be unpacked into suitable nested columns.

The Corr object provides two methods to perform correlation calculations:

  • with — computes correlations between the initially selected columns and a second set of columns.

  • withItself — computes pairwise correlations within the initially selected columns.

Each method returns a square or rectangular correlation matrix represented by a DataFrame, where rows and columns correspond to the selected column sets, and each cell contains the Pearson correlation coefficient between the corresponding pair of columns.

To compute correlations between all suitable columns in the DataFrame, use DataFrame.corr().

Check out Grammar.

This can include column groups and nested columns.

See also: Selecting Columns.

For more information, see: See corr on the documentation website.

This Corr Overload

Select or express columns using the Columns Selection DSL.

This DSL is initiated by a Columns Selector lambda, which operates in the context of the Columns Selection DSL and expects you to return a SingleColumn or ColumnSet (so, a ColumnsResolver). This is an entity formed by calling any (combination) of the functions in the DSL that is or can be resolved into one or more columns.

The Columns Selection DSL allows using Extension Properties for specifying columns type- and name-safe.

Check out: Columns Selection DSL Grammar

    

See Column Selectors on the documentation website.

The function is available for numeric- and Boolean columns. Boolean values are converted into 1 for true and 0 for false. All other columns are ignored. If a ColumnGroup instance is passed as the target column for correlation, it will be unpacked into suitable nested columns.

Examples

// Compute correlations between the "age" column and the "weight" and "height" columns
df.corr { age }.with { weight and height }

// Compute pairwise correlations between all columns of type `Number`
df.corr { colsOf<Number>() }.withItself()

Return

A Corr intermediate object with the selected columns.

Parameters

columns

The Columns Selector used to select the columns of this DataFrame to compute a correlation.


fun <T> DataFrame<T>.corr(vararg columns: String): Corr<T, Any?>

Calculates the Pearson pairwise correlation between values in the specified columns.

This function does not compute the correlation immediately. Instead, it defines the primary set of columns and returns a Corr instance that allows configuring how the correlation should be computed.

The function is available for numeric- and Boolean columns. Boolean values are converted into 1 for true and 0 for false. All other columns are ignored. If a ColumnGroup instance is passed as the target column for correlation, it will be unpacked into suitable nested columns.

The Corr object provides two methods to perform correlation calculations:

  • with — computes correlations between the initially selected columns and a second set of columns.

  • withItself — computes pairwise correlations within the initially selected columns.

Each method returns a square or rectangular correlation matrix represented by a DataFrame, where rows and columns correspond to the selected column sets, and each cell contains the Pearson correlation coefficient between the corresponding pair of columns.

To compute correlations between all suitable columns in the DataFrame, use DataFrame.corr().

Check out Grammar.

This can include column groups and nested columns.

See also: Selecting Columns.

For more information, see: See corr on the documentation website.

This Corr Overload

Select single or multiple columns using their names as Strings. (String API).

The function is available for numeric- and Boolean columns. Boolean values are converted into 1 for true and 0 for false. All other columns are ignored. If a ColumnGroup instance is passed as the target column for correlation, it will be unpacked into suitable nested columns.

Examples

// Compute correlations between the "age" column and the "weight" and "height" columns
df.corr { age }.with { weight and height }

// Compute pairwise correlations between all columns of type `Number`
df.corr { colsOf<Number>() }.withItself()

Return

A Corr intermediate object with the selected columns.

Parameters

columns

The Column Names used to select the columns of this DataFrame to compute a correlation.


fun <T, C> DataFrame<T>.corr(vararg columns: KProperty<C>): Corr<T, C>
fun <T, C> DataFrame<T>.corr(vararg columns: ColumnReference<C>): Corr<T, C>

Deprecated

It's recommended to migrate to the String or Extension Properties Access API https://kotlin.github.io/dataframe/apilevels.html