Say I have data.frame a
I use
m.fit <- lm(col2 ~ col3 * col4, na.action = na.exclude)
col2
has some <
I got this error when I inverted the arguments when calling reformulate
and use the formula in my lm
call without checking, so I had the wrong predictor and response variable.
Make sure you don't have any 0 in your dependent variable.
Try changing the type of col2 (and all other variables)
col2 <- as.integer(col2)
I solved this type of problem by resetting my options.
options(na.action="na.exclude")
or
options(na.action="na.omit")
I checked my settings and had previously changed the option to
"na.pass" which didn't drop my y observations with NAs (where y~x
).
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!
Another thing to watch out for is using functions like log() or sin() make your x's and y's inf. eg. log 0 = 0 or sin(pi) = 0.