0

I am getting an error while executing the exact same code given in my textbook on my machine. It is the simple pairs function code.

my code is pairs(college[, 1:10])

The error I am getting:

Error in pairs.default(college[, 1:10]) : non-numeric argument to 'pairs'

onlyphantom
  • 8,606
  • 4
  • 44
  • 58
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Mar 12 '21 at 05:06

1 Answers1

0

Your college[,1:10] dataset contain columns that are not numeric.

Run:

str(college[,1:10])

And inspect the column types in your dataframe.

Since pairs matrix essentially creates a matrix of scatterplot using each combination of columns, it expect a dataframe with numeric columns only.

This makes sense, if you consider the fact that you wouldn't create a scatterplot using Student Gender (a categorical variable, i.e non-numeric) against Student Age for example. It doesn't make sense.

In your case, this error:

Error in pairs.default(college[, 1:10]) : non-numeric argument to 'pairs'

Tells you that among the 10 columns, one or more of these are non-numeric. Either remove these columns in your call to pairs() or perform explicit coercion using as.numeric().

onlyphantom
  • 8,606
  • 4
  • 44
  • 58