Suppose to calculate correlation of dataset mtcars we can use corr <- round(cor(mtcars), 1), or calculate and plot a correlation matrix using corrplot(cor(mtcars). However, the product is pairwise correlation. Is it possible to calculate non-pairwise correlation between spesific set of columns i.e., in mtcars correlation between columns 1:3 (mpg, cyl, disp) VS column 4:8 (hp, drat, wt, qsec, vs).
Please suggest any method.
I have a data set containing 120 columns. I want to calculate/plot correlation matrix (Spearman correlate) of columns 1:50 with rest of the columns (i.e., 51-120). Please tell me the solution, if possible, by using cor, or packages i.e., corrplot, ggcorrplot.
Thanks in anticipation.
You can do this using the
corfunction, just need to specify the second parameter. Example:The result:
NOTE: Using the
corrplotfunction with theorderparameter will produce errors or a wrong plot. If you need to reorder the variables (ex.: withhclust), reorder the correlation matrix before passing it tocorrplot.