Skip to content

Commit

Permalink
Update Xtestmerger.R
Browse files Browse the repository at this point in the history
The check that both test and X will have matching levels for factor columns breaks if the levels are the same but in the test some level is not present in the data (which I can imagine happens a lot since the test set is always much smaller). By removing the droplevels function now we really compare the levels on the factors and not the appearance of levels in the data.
  • Loading branch information
rragundez committed Oct 2, 2017
1 parent 441a9f8 commit 66b6341
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions R/Xtestmerger.R
Expand Up @@ -22,8 +22,8 @@ Xtestmerger = function(X,test,inbag=NULL,y=NULL) {
#return unmatched levels of test in X
FUN = function(xl,tl) tl[which(is.na(match(tl,xl)))], #test levels not in x
#for factor column, get all used levels
lapply(lapply( X[factor.ind],droplevels),levels),#xl
lapply(lapply(test[factor.ind],droplevels),levels),#tl
lapply( X[factor.ind],levels),#xl
lapply(test[factor.ind],levels),#tl
SIMPLIFY = FALSE, USE.NAMES = TRUE
)
unmatchedLevelsCount = sapply(unmatchedTestLevels,length)
Expand Down Expand Up @@ -55,4 +55,4 @@ Xtestmerger = function(X,test,inbag=NULL,y=NULL) {
},
isTrain = c(rep(T,dim(X)[1]),rep(F,dim(test)[1]))
))
}
}

0 comments on commit 66b6341

Please sign in to comment.