[R] Converting a categorical variable to multiple dichotemous variables

Shane Phillips SPhillips at Lexington1.net
Tue Apr 12 14:17:23 CEST 2011


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...

cat1	cat2	cat3	cat4
1	0	0	0
1	0	0	0
0	0	1	0
0	1	0	0
0	0	0	1


Thanks in advance!

Shane



More information about the R-help mailing list