0

I am new to R and to actually asking a question in Stack Overflow. I looked at several similar questions, but they did not seem to apply to help my situation. I am trying to make a linear model with the lm() function, but I get an error returned that states one of my data frame columns is able to be found:

library(SemiPar) # Contains Janka data

data(janka)
names(janka) <- c("Density", "Hardness")

janka.ls1 <- lm(hardness~dens, Data = janka)

I get the following error after running the final line:

Error in eval(predvars, data, env) : object 'Hardness' not found

As you can see, I named one of the two columns 'Hardness' and when I view the data I also see that the names do match. Further, when I try running the code using the original data column name, it still has the same issue.

Thanks for your help!!

shwalters
  • 23
  • 4
  • 1
    You've renamed the column name `hardness` to `Hardness`, but then use the old name `hardness` in your `lm` model. Ditto for `dens`. So you need to do `lm(Hardness ~ Density, data = janka)`. Vote to close as simple typo. – Maurits Evers Nov 17 '19 at 20:43
  • R is case sensitiive. In addition to the problem already discssed in the last comment the code in the question uses `Data = ` whereas what is needed is `data = ` . – G. Grothendieck Nov 17 '19 at 22:34
  • Hello. Thanks to both of you. I actually added a comment stating that I realized that it was because of the capitalization of `Data= ` (I copied the wrong line from my code, I did actually use `Hardness` and `Density`. For some reason, someone deleted my comment that explained my error. Not sure why they did that. Thanks for your help! I also vote to close. – shwalters Nov 19 '19 at 13:56

0 Answers0