Re: [R] Efficiently create dummy

2009-03-23 Thread Chuck Cleland
On 3/23/2009 5:44 AM, Rob Denniker wrote: > What's the neat way to create a dummy from a list? > The code below is not replicable, but hopefully self-explanatory... > > d$treatment<-rep(1,length(d)) > > notreat<-c("AR", "DE", "MS", "NY", "TN", "AK", "LA", "MD", "NC", "OK", "UT", > "VA") > > #i

Re: [R] Efficiently create dummy

2009-03-23 Thread Dimitris Rizopoulos
well, you can first define a factor, and the use model.matrix(), e.g., fc <- factor(c("AR", "DE", "MS", "NY")) model.matrix(~ fc) for more info check ?model.matrix(), e.g., if you want to change the contrasts. I hope it helps. Best, Dimitris Rob Denniker wrote: What's the neat way to cre

[R] Efficiently create dummy

2009-03-23 Thread Rob Denniker
What's the neat way to create a dummy from a list? The code below is not replicable, but hopefully self-explanatory... d$treatment<-rep(1,length(d)) notreat<-c("AR", "DE", "MS", "NY", "TN", "AK", "LA", "MD", "NC", "OK", "UT", "VA") #i would really like this to work: d$treatment[d$st==any(notre