This works:


> model.matrix(~I(pos>3),data=data.frame(pos=c(1:5)))
  (Intercept) I(pos > 3)TRUE
1           1              0
2           1              0
3           1              0
4           1              1
5           1              1
attr(,"assign")
[1] 0 1
attr(,"contrasts")
attr(,"contrasts")$"I(pos > 3)"
[1] "contr.treatment"


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

 
--------------------------------------------------------------------
  Trevor Hastie                                  hastie@stanford.edu  
  Professor, Department of Statistics, Stanford University
  Phone: (650) 725-2231 (Statistics)          Fax: (650) 725-8977  
  (650) 498-5233 (Biostatistics)   Fax: (650) 725-6951
  URL: http://www-stat.stanford.edu/~hastie  
  address: room 104, Department of Statistics, Sequoia Hall
           390 Serra Mall, Stanford University, CA 94305-4065  
--------------------------------------------------------------------

	[[alternative HTML version deleted]]


