[R] Creating Dummy Variables in R

Tom Fletcher tom.fletcher.mp7e at statefarm.com
Wed Dec 16 17:21:04 CET 2009


Is your variable Clarity a categorical with 4 levels? Thus, the need for
k-1 (3) dummies? Your error may be the result of creating k instead of
k-1 dummies, but can't be sure from the example.

In R, you don't have to (unless you really want to) explicitly create
separate variables. You can use the internal contrast functions. 

See

?contr.treatment

Which is dummy coding by default. You can specify which group is the
reference group. 

Alternatively, if you prefer effects coding, you can see
?contr.sum 

There are others as well. 

Tom Fletcher



-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of whitaker m. (mw1006)
Sent: Wednesday, December 16, 2009 8:59 AM
To: r-help at r-project.org
Subject: [R] Creating Dummy Variables in R

Hi,
I am trying to create a set of dummy variables to use within a multiple
linear regression and am unable to find the codes within the manuals.

For example i have:
Price     Weight     Clarity
                             IF      VVS1    VVS2
500        8             1         0          0
1000      5.2          0         0          1
864        3              0        1          0
340        2.6          0         0          1
90          0.5          1         0          0 
450        2.3          0         1          0

Where price is dependent upon weight (single value in each observation)
and clarity (split into three levels, IF, VVS1, VVS2).
I am having trouble telling the program that clarity is a set of 3 dummy
variables and keep getting error messages, what is the correct way?

Any helps is greatly appreciated.
Matthew

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list