Replaced ncol(xdat.numeric) with k which is always defined even when
there exist no numeric variables (may require more tweaking in this case)