Programmers learn & share
0 votes

Problem :

Suppose I have data.frame a

And I am using following code <- lm(col2 ~ col3 * col4, na.action = na.exclude)

Here the col2 has some NA values And col3,col4 have values less than 1.

I am getting following error:

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

I have also checked the mailing list and I found that the error is because of the NA values present in col2  I also tried using na.action=na.exclude/omit/pass but none of them seem to work. I have tested lm again on the first 10 entries, definitely not because of the NAs. Problem with this warning is interpreted by every google results is pointing towards the NA values.

Have I misinterpreted the error ?

by (6.9k points)   | 492 views

1 Answer

0 votes

Solution :

I had encountered the same error when my equivalent of col2 was an integer64 rather than an integer and while using natural and polynomial splines, splines::bs and splines:ns example as follows: <- lm(col1 ~ ns(col2)) <- lm(col1 ~ bs(col2, degree = 3))

Converting it to a standard integer really worked for me: <- lm(col1 ~ ns(as.integer(col2))) <- lm(col1 ~ bs(as.integer(col2), degree = 3))
by (36.1k points)  
2,227 questions
2,734 answers
241 users