The predict
method for dummyVars
from the caret
library has documentation that clearly states:
"The predict function produces a data frame."
However, every example that I've produced appear to only be a matrix. The following code is an example of this:
>input<-data.frame(id=c(1, 2, 3), direction=c('up', 'down', 'down'))
>dmy<-dummyVars(" ~ .",input)
>output<-predict(dmy, newdata=input)
>output
id direction.down direction.up
1 1 0 1
2 2 1 0
3 3 1 0
>class(output)
[1] "matrix"
>is.data.frame(output)
[1] FALSE
>is.matrix(output)
[1] TRUE
Everything that I can see indicates that the documentation is wrong and that the predict
function is really returning a matrix rather than a data frame. What's going on?