0

I am trying to create a linear model using R. I have imported a dataset from Excel that had some blank cells. I copied and pasted certain cols that all contained the same number of rows. I cannot create the model as I am getting an error message. I am not even using the lm.fit function.

I have tried using only one independent variable but still does not work.

 mod1 <- lm(Price_Change~SurpEPS+SurpNI+SurpRev)

Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : NA/NaN/Inf in 'y' In addition: Warning message: In storage.mode(v) <- "double" : NAs introduced by coercion

Claudiu Papasteri
  • 2,469
  • 1
  • 17
  • 30
  • Possible duplicate: https://stackoverflow.com/questions/8415778/linear-model-function-lm-error-na-nan-inf-in-foreign-function-call-arg-1 – Claudiu Papasteri Jul 08 '19 at 18:59
  • 1
    `lm` uses `lm.fit` internally. Typically you call `lm` with a data argument, e.g., `lm(Price_Change~SurpEPS+SurpNI+SurpRev, data = name_of_your_data)`. And maybe post `str(your_data)` to see if we can find any irregularities. – Gregor Thomas Jul 08 '19 at 18:59
  • Since I used the attach function, I did not have to enter the data in the same line. I did try to do so, but the error persisted. – pablosanchez17 Jul 08 '19 at 19:06
  • Maybe the blank cells were read in as characters or factors. – Rui Barradas Jul 08 '19 at 19:23
  • 1
    I'd strongly recommend avoiding `attach` - great way for columns of data to get out of sync and cause bugs. – Gregor Thomas Jul 08 '19 at 19:35

0 Answers0