error in xgb.Dmatrix

I want to create xgb.Dmatrix object. At the first step, I convert data.frame into model.matrix:

new_tr <- model.matrix(~.+0,data = train[,-c(21)]) 
labels <- train$default 

and then write following code to create xgb.Dmatrix:

dtrain <- xgb.DMatrix(data = as.matrix(new_tr), label = labels) 

I get following error:

Error in setinfo.xgb.DMatrix(dmat, names(p), p[[1]]) : The length of labels must equal to the number of rows in the input data

how to handle this problem?

seems odd...
what is the length of labels ?
how many rows in train?
and new_tr ?

I have handled this error already. There were some missing value in data, that was removed after model.matrix and length of new_tr was less than length of labels. I initially delete missing values and it works