I am trying to perform a correlation matrix on an all numerical dataset, imported from a .csv with headers specified as row 1:

bball3 = 
   "/Users/Eileen/Documents/AA_Semester 2/Mathematica/Final \
Project/Seasons_Stats.csv", {"CSV", "Dataset"}, "HeaderLines" -> 1] ;

The data set has some categorical features so I have created a subsetted data set with just the numeric features:

numericDATA = bball3[All, 4 ;;];

But I am unable to call on the Correlation[] function to get a Correlation Matrix, when I do I get the following error: enter image description here

Does anyone have suggestions? Thanks

  • $\begingroup$ After removing ` {"CSV", "Dataset"},` it seems to work just fine for 13.0.1 (Windows 10). $\endgroup$
    – JimB
    Commented Apr 26, 2022 at 22:53
  • 1
    $\begingroup$ I suspect you must have used MatrixForm on bball3 prior to using Correlation because without doing so one gets the error Correlation::arg1: The first argument must be either a vector, a matrix, or a multivariate distribution. But MatrixForm doesn't fix that error. $\endgroup$
    – JimB
    Commented Apr 26, 2022 at 23:11

1 Answer 1


Correlation is not tuned to take Dataset but there are ways to calculate.


ds =
   AssociationThread[Alphabet[][[;; 5]] -> #] & /@
    RandomReal[{100, 200}, {30, 5}]

Most basic is to get the Values and then call Correlation

Correlation@Normal[Values@ds] // MatrixForm

enter image description here

However, if you want to retain Dataset and the keys then

 {Keys@*First, Values/*Correlation}/*
   AssociationThread[#1 -> Map[r |-> AssociationThread[#1, r]]@#2] &

enter image description here

Hope this helps.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.