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.