[R] Converting a categorical variable to multiple dichotemous variables

2011-04-12 Thread Shane Phillips
I have a categorical variable in a dataframe similar to the following... cat 1 1 3 2 4 I need to convert it to 4 dichotemous variables for each observations like... cat1cat2cat3cat4 1 0 0 0 1 0 0 0 0 0 1 0 0 1 0

Re: [R] Converting a categorical variable to multiple dichotemous variables

2011-04-12 Thread andrija djurovic
hi: here is one solution: cat-as.factor(c(1,1,3,2,4)) model.matrix(~cat-1,cat) cbind(cat,model.matrix(~cat-1,cat)) Andrija On Tue, Apr 12, 2011 at 2:17 PM, Shane Phillips sphill...@lexington1.netwrote: I have a categorical variable in a dataframe similar to the following... cat 1 1 3 2