[R] Coding categorical -> dummy

Samir Messad messad at cirad.cirad.fr
Wed May 9 17:25:15 CEST 2001


Dear R-Users,

I have a data frame with several categorical variables. I want to create a
new data frame with dummy variables (with all levels).
I know the function model.matrix (see below) but it works only for one
categorical variable :

> tt <- c("a","a","b","a","c")
> tt <- factor(tt)
> model.matrix(~ tt - 1)

is there anyone who have write such function ?
Thanks for your help.

Samir Messad


Samir Messad    E-Mail : messad at cirad.fr
Statisticien
CIRAD-EMVT
TA 30/A
Programme Productions Animales
Campus de Baillarguet
34398 Montpellier cedex 5 (France)

Tél :  +33 (0)4-67-59-38-44
Fax : +33 (0)4-67-59-38-25
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list