Linear model function lm() error: NA/NaN/Inf in foreign function call (arg 1)

Say I have data.frame a

I use

m.fit <- lm(col2 ~ col3 * col4, na.action = na.exclude)

col2 has some NA values, col3 and col4 have values less than 1.

I keep getting

Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
NA/NaN/Inf in foreign function call (arg 1)

I’ve checked the mailing list and it appears that it is because of the NAs in col2 but I tried using na.action=na.exclude/omit/pass but none of them seem to work. I’ve tested lm again on first 10 entries, definitely not because of the NAs. Problem with this warning is every google results seem to be pointing at NA.

Did I misinterpret the error or am I using lm wrongly?

Data is at kaggle. I’m modelling MonthlyIncome data using linear regression (as I couldn’t get a certain glm family to work). I’ve created my own variables to use but if you try to model MonthlyIncome with variables already present it fails.

Leave a Comment