A correlation matrix is a type of table showing correlation coefficients between variables. Here, each cell in the table shows the correlation between two variables. This matrix is used correlation matrix is used to summarize data. In this article we, will be looking at the approach to get the correlation matrix from a given DataFrame of the same data type in R Programming language.
cor() method can be used for creating a correlation matrix from the given DataFrame of the same data type using the R language. This is one of the easiest methods to create the correlation matrix from the dataframe as here the user just need to call the cor() function with the name of the dataframe as its parameter and further the cor() function with the specified parameter will be returning to the user the correlation matrix of the given data-frame with the same data frame.
Syntax: cor(x,use = “everything”,method = c(“pearson”, “kendall”, “spearman”))
- x:-a numeric vector, matrix, or data frame.
- use:-an optional character string giving a method for computing covariance in the presence of missing values.
- method:-a character string indicating which correlation coefficient is to be computed.
It will return the correlation matrix.