作为输入我正在尝试这个:
df <- data$Sex
data$Sex <- gsub("M|F", "MF", data$Sex)
data$Length[which(is.nan(data$Length))] = NA
data$Length[which(data$Length==Inf)] = NA
data$Sex[which(is.nan(data$Sex))] = NA
data$Sex[which(data$Sex==Inf)] = NA
model4a <- lm(data$Sex ~ data$Length,na.action=na.exclude)
plot(model4a,pch=16,which=1)
cf <- round(coef(model4a), 7)
eq <- paste("Sex = ",cf[1],"+", abs(cf[2]),"* Length")
mtext(eq, 3, line=-2)
但是我收到了以下错误:
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
我做错了什么。我看到这个网站上已经存在类似的问题了,但是他们的解决方案对我没有帮助。非常感谢!我已经为我正在进行的文件提供了一个链接操作如下: File