How to find correlations among feature variables in R?

This recipe helps you correlate the fields in a dataset to determine the relationship between them and pick the right features for modelling.
In [ ]:
# -------------------------------------------------
# How to find correlations among feature variables in R
# -------------------------------------------------
# load library and data
library(mlbench)
library(Hmisc)

data(mtcars)
dim(mtcars)

par(mfrow=c(1,1))

# Correlations/covariances among numeric variables 
# Use listwise deletion of missing data. 
cor(mtcars, use="complete.obs", method="kendall") 
cov(mtcars, use="complete.obs")

# Correlations with significance levels
rcorr(as.matrix(mtcars), type="pearson")

# Correlation matrix from mtcars
# with mpg, cyl, and disp as rows 
# and hp, drat, and wt as columns 
x <- mtcars[1:3]
y <- mtcars[4:6]
cor(x, y)