[R] problem with model.matrix
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Fri Jun 25 00:45:23 CEST 2004
"Trevor Hastie" <hastie at stanford.edu> writes:
> This does not:
>
> > model.matrix(~I(pos>3),data=data.frame(pos=c(1:2)))
> Error in "contrasts<-"(`*tmp*`, value = "contr.treatment") :
> contrasts can be applied only to factors with 2 or more levels
Oh yes it does:
> model.matrix(~I(pos>3),data=data.frame(pos=c(1:2)))
(Intercept) I(pos > 3)TRUE
1 1 0
2 1 0
attr(,"assign")
[1] 0 1
attr(,"contrasts")
attr(,"contrasts")$"I(pos > 3)"
[1] "contr.treatment"
(RedHat,SuSE,x86,amd64)
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list