0

I'm trying to debug a call to kmeansvar in some data I'm working on, but before I can even try to reproduce the issue, I have to figure out what this error message from recodqual() is saying:

Error in recodqual(X.quali) : There are columns in X.quali where all the categories are identical

The source is fairly short, but without comments, and I don't understand the test condition or the error message:

recodqual <-
function(X)
    {
        X <- as.matrix(X)
        GNA <- tab.disjonctif.NA(X)
        G <- replace(GNA,is.na(GNA),0)
        ns <- apply(G,2,sum)
        nmiss <- apply((apply(GNA,2,is.na)),2,sum)
        n <- nrow(X)
        if(sum((n-nmiss)==ns)!=0) stop("There are columns in X.quali where all the categories are identical")
        return(G)   
}

What is the stop message trying to say, and what is it testing?

  • I thought it was failing because of identical columns, but I got this error with a data.table of only two different categorical variables.
  • If made sure I had a data.table with two different categorical variables with more than one unique value per column, the call succeeded.
  • However, filtering the categorical subset by uniqueness in rows resulted in the call failing as above:

    cat.cols <- Filter(function(col) { 
      !is.numeric(main.data[,get(col)]) &
        length(main.data[,unique(get(col))]) > 1
    }, colnames(main.data))
    # followed by call using main.data[,cat.cols,with=FALSE]
    

I'll add some test data to reproduce shortly.

bright-star
  • 6,016
  • 6
  • 42
  • 81
  • What packages are you using? `tab.disjonctif.NA` is not a base `R` function, at least that I can find. Without knowing what that function does, it is really hard to debug this. Based on the output message though, I would guess the error occurs when all the values in a column are identical. – Barker May 16 '17 at 22:41
  • This is from PCAmixdata. – bright-star May 16 '17 at 23:01

0 Answers0