R:如何在具有NA值的表上运行回归?
当前,我的错误语句如下所示:R:如何在具有NA值的表上运行回归?,r,regression,na,lm,R,Regression,Na,Lm,当前,我的错误语句如下所示: NAs introduced by coercionError in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : NA/NaN/Inf in 'x' 这是我正在使用的代码: model <- lm(merged$Country.or.region ~ ., data = merged, na.action = na.pass) model我猜您的列是Country.o
NAs introduced by coercionError in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
NA/NaN/Inf in 'x'
这是我正在使用的代码:
model <- lm(merged$Country.or.region ~ ., data = merged, na.action = na.pass)
model我猜您的列是Country.or.region
是一个字符,您需要将其转换为一个因子,并使用二元逻辑回归:
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)
data=iris
数据$Species=as.character(数据$Species)
lm(物种,数据=数据)
lm拟合误差(x,y,偏移量=偏移量,singular.ok=singular.ok,…):
“y”中的NA/NaN/Inf
此外:警告信息:
在存储模式(v)中您好,欢迎使用堆栈溢出!您能否使用函数dput()
提供一些示例数据,以方便人们帮助您?非常感谢!非常感谢。我将来一定会这样做。