Hi,
I'm trying to get sparse.model.matrix to retain unused levels. I can't
seem to get this working through the most obvious routes such as
specifying drop.unused.levels = FALSE in the model.frame or trying to
pass all levels in xlev,which is an argument to sparse.model.matrix
(see code below).
Any help would be gratefully received.
Cheers,
Jarrod
fac<-factor(rep(1:10,10), levels=1:100)
mf<-model.frame(~fac, drop.unused.levels = TRUE)
mf2<-model.frame(~fac, drop.unused.levels = FALSE)
dim(model.matrix(~fac, mf))
dim(model.matrix(~fac, mf2))
dim(model.matrix(~fac, xlev=list(fac=1:10)))
dim(model.matrix(~fac, xlev=list(fac=1:100)))
dim(sparse.model.matrix(~fac, mf))
dim(sparse.model.matrix(~fac, mf2))
dim(sparse.model.matrix(~fac, xlev=list(fac=1:10)))
dim(sparse.model.matrix(~fac, xlev=list(fac=1:100)))
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.