1 votes

non-numeric argument to 'pairs' en R

I was trying to make a correlation matrix with the command scatterplotMatrix() in R and I get this error:

scatterplotMatrix(a_heterophylla_NAY_SIN, spread=FALSE, lty.smooth=2, main="Matriz correlaciones") Error in pairs.default(x, labels = var.labels, cex.axis = cex.axis, cex.main = cex.main, :
non-numeric argument to 'pairs'

What does it mean and how do I solve it? Please help!


Patricio Moracho Points 24098

I will try to answer your question based on the information you provided. Fundamentally the problem is one of data, particularly in a_heterophylla_NAY_SIN the error is triggered when scatterplotMatrix() internally invokes pairs() assigning the parameter x with your object a_heterophylla_NAY_SIN if you see the documentation:

x: the coordinates of points given as numeric columns of a matrix or data frame. Logical and factor columns are converted to numeric in the same way that data.matrix does.

That is, an array or dataframe is expected and fundamentally all values must be "mapped" to numeric values. Reviewing the code of pairs() we see:

if (!is.matrix(x)) {
        x <- as.data.frame(x)
        for(i in seq_along(names(x))) {
            if(is.factor(x[[i]]) || is.logical(x[[i]]))
               x[[i]] <- as.numeric(x[[i]])
                stop("non-numeric argument to 'pairs'")
    } else if (!is.numeric(x)) stop("non-numeric argument to 'pairs'")

In other words, or a_heterophylla_NAY_SIN is a NON numeric matrix or an object that even if mapped as a dataframe, some of its columns are not numeric. The solution then would be to "normalize". a_heterophylla_NAY_SIN and eventually convert any non-numeric value into a Factor, so that it can be processed correctly.


HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by: