0

Currently, my error statement looks like this:

NAs introduced by coercionError in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
  NA/NaN/Inf in 'x'

This is the code that I'm using:

model <- lm(merged$Country.or.region ~ ., data = merged, na.action = na.pass)

I've also tried using na.exclude and na.omit based on some advice given elsewhere online. Am I doing something wrong within the lm parentheses?

Anders Zhou
  • 89
  • 1
  • 8
  • 1
    Hi and welcome to Stack Overflow! Could you provide some sample data using the function `dput()` so that people are facilitated to help you? Many thanks! – Ric S Mar 24 '20 at 11:08
  • Thank you! I will be sure to do this in the future Ric. – Anders Zhou Mar 25 '20 at 00:10

1 Answers1

1

I am guessing your column is Country.or.region is a character, you need to convert it into a factor, and binary and use logistic regression:

data = iris
data$Species = as.character(data$Species)

lm(Species ~ .,data=data)
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

data$Species = ifelse(data$Species=="versicolor","Yes","No")
data$Species = factor(data$Species)
glm(Species ~ .,data=data,family=binomial)
StupidWolf
  • 45,075
  • 17
  • 40
  • 72