[R] Creating Dummy Variables in R

S Devriese sdmaillist at gmail.com
Wed Dec 16 16:16:43 CET 2009


On 12/16/2009 03:58 PM, whitaker m. (mw1006) wrote:
> 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?
> 

Without an example of your code, it's a bit difficult. But it might be
easier to use one variable "clarity" with three possible values (IF,
VVS1, VVS2), defined as a factor.
lm(Price ~ Weight + Clarity) should then do the trick (unless you
explicitly want to use a different dummy coding than the default)

Stephan




More information about the R-help mailing list