[R] Odp: Creating Dummy Variables in R

Peter Dalgaard p.dalgaard at biostat.ku.dk
Wed Dec 16 23:57:27 CET 2009


Nordlund, Dan (DSHS/RDA) wrote:
>> -----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 2:14 PM
>> To: Nikhil Kaza; Petr PIKAL
>> Cc: r-help at r-project.org
>> Subject: Re: [R] Odp: Creating Dummy Variables in R
>>
>> I have a much larger dataset than in my original email (attached - price dependent
>> upon weight, Clarity (different levels IF-SI2), colour(levels D-L) and Cut (ideal-fair),
>> and tried the regression command:
>>
>>> diamond.lm<-
>> lm(price~weight+IF+VVS1+VVS2+VS1+VS2+SI1+SI2+I1+I2+D+E+F+G+H+I+J+K
>> +L+ideal+excellent+very.good+good+fair, data="Diamonds2.txt")
>>
>> Error in eval(predvars, data, env) : invalid 'envir' argument
>>
>> Which lead to the error message below the command. I have tried searching for
>> this, and assumed this was down to having categrocial variables within the data, is
>> this a correct assumption or am i doing something else wrong? Apologies if this is a
>> bit of a basic question!
>>
>> Thanks again,
>> Matthew
> 
> You need to read your data from Diamonds2.txt into a dataframe first before running the lm() function.  What does your file Diamonds2.txt look like? 

And, to put it more bluntly, he needs to study some introductory R text 
rather more carefully to learn how the pieces fit together.

(Although I can see that the error may be cryptic to a beginner, I am at 
a loss to explain what kind of leap of logic led him to believe that 
dummy variables had _anything_ to do with it. For Heaven's sake, he must 
be getting the same error if he leaves out the dummy variables!)

-- 
    O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
  (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907




More information about the R-help mailing list