[R] problem with model.matrix

Liaw, Andy andy_liaw at merck.com
Fri Jun 25 00:51:01 CEST 2004


> From: Peter Dalgaard
> 
> "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:

Ditto here.  (WinXPPro/R-1.9.0/P3)

Andy
 
> >  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
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
>




More information about the R-help mailing list