"Doran, Harold" <[EMAIL PROTECTED]> writes:
> Is there an efficient way to create a series of dummy codes from a single variable?
> For example, I have a variable, “grade” = {2, …, 12}. I want to create k-1
> dummy codes for grade such that grade 2 is the base (i.e, grade 2 =0).
>
> I am hoping that the new variables can be labeled as grade.3, grade.4 etc. I'll then
> use
>
> grade <- paste("grade.", 3:12, sep="") in as.formula to build the model.
>
> Thanks,
>
> Harold
>
>
> [[alternative HTML version deleted]]
[unfortunately, at least to some of us, the above is only slightly
less unreadable...]
No, you don't want to do that. Instead, do
fgrade <- factor(grade)
lm(y ~ fgrade) # or glm or coxph or whatever
If you really want the dummy variables, look at
model.matrix(~fgrade)
(minus the first (Intercept) column)
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907
______________________________________________
[EMAIL PROTECTED] 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