possible bug if input is matrix and has early NA
Opened this issue · 0 comments
ivokwee commented
I get an error Error in if (n == 0) stop("data (x) has 0 rows")
if the input is a matrix and has NA in the first few entries. If the input is cast to a data.frame the error disappears. This is a possible bug.
How to replicate:
> X = matrix( c(1,NA, 1,NA, 1, 1), 2, 3)
> missForest::missForest(X)$ximp
Error in if (n == 0) stop("data (x) has 0 rows") :
argument is of length zero
> X = matrix( c(1,NA, 1,NA, 1, 1), 2, 3)
> missForest::missForest( as.data.frame(X))$ximp
V1 V2 V3
1 1 1 1
2 1 1 1
Possible cause
In the code if (is.numeric(xmis[[t.co]]))
(and elsewhere) will not work correctly if the input is a matrix and not a dataframe. For a numerical matrix X the X[[1]] will not take the first column but only the first element X[1,1]. Then when an element of X is NA, is.numeric(NA) will happen and code will not run correctly.
Possible solution
Either cast input always to data.frame, or test for is.numeric(xmis[,t.col])