Learn R Programming

SparkR (version 3.1.2)

corr: corr

Description

Computes the Pearson Correlation Coefficient for two Columns.

Usage

corr(x, ...)

# S4 method for Column corr(x, col2)

# S4 method for SparkDataFrame corr(x, colName1, colName2, method = "pearson")

Arguments

x

a Column or a SparkDataFrame.

...

additional argument(s). If x is a Column, a Column should be provided. If x is a SparkDataFrame, two column names should be provided.

col2

a (second) Column.

colName1

the name of the first column

colName2

the name of the second column

method

Optional. A character specifying the method for calculating the correlation. only "pearson" is allowed now.

Value

The Pearson Correlation Coefficient as a Double.

See Also

Other aggregate functions: avg(), column_aggregate_functions, count(), cov(), first(), last()

Other stat functions: approxQuantile(), cov(), crosstab(), freqItems(), sampleBy()

Examples

Run this code
# NOT RUN {
df <- createDataFrame(cbind(model = rownames(mtcars), mtcars))
head(select(df, corr(df$mpg, df$hp)))
# }
# NOT RUN {
# }
# NOT RUN {
corr(df, "mpg", "hp")
corr(df, "mpg", "hp", method = "pearson")
# }

Run the code above in your browser using DataLab