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

后端 未结 10 1204
天涯浪人
天涯浪人 2020-12-03 09:49

Say I have data.frame a

I use

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

col2 has some <

10条回答
  •  青春惊慌失措
    2020-12-03 10:35

    I know this thread is really old, but the answers don't seem complete, and I just ran into the same problem.

    The problem I was having was because the NA columns also had NaN and Inf. Remove those and try it again. Specifically:

    col2[which(is.nan(col2))] = NA
    col2[which(col2==Inf)] = NA
    

    Hope that helps your 18 month old question!

提交回复
热议问题