1.导入数据时,将数据框中数据转化数值型报错
方案:unlist()
as.numeric.(unlist())
2.无法使用rstudio或者R安装程序包
Warning in install.packages:unable to access index for respository
原因可能是镜像问题,重新选一个镜像
方案:
chooseCRANmirror() #选择相应的镜像——国内最好
再次运行install.packages()
3.更新R报错
Error in file(con, “r”) : 无法打开链结
此外: Warning message:
In file(con, “r”) : InternetOpenUrl失败:’安全频道支持出错’
方案:
updateR(fast=TRUE,cran_mirror="https://mirrors.ustc.edu.cn/CRAN/")
使用这个后R成功更新到3.6.3版本
4.数据筛选时报错
Error in [.data.frame(L2, L2$ALF == 0) : undefined columns selected :调用没有定义的列
参考解决办法
1.使用read.csv解决
但其报错原因是因为用read.table()读取CSV文件
对我而言—无效
2.使用条件语句选择值
A1<-L2[L2$ALF==0,]
问题解决
后来神奇的发现,之前的代码也是可以运行,是自己忘了加个逗号
A1<-L2[L2$ALF==0,]
参考转载:有意思的undefined columns selected
5.预测值时报错
预测值时报错,虽然只是警告信息,但后续操作时一直报错
glm1<-glm(g[,17]~g[,1]+g[,6]+g[,10]+g[,12]+g[,14]+g[,15]+g[,16],
family=binomial(link = logit),traindata3)
p<-predict(glm1, newdata = testdata, type = "response")
Warning message:
'newdata'必需有1686行 但变量里有3933行
原因:在构建线性模型时用datasetname $ variablename模式引用变量
解决方法:将datasetname $ variablename换为变量名+变量名
glm1<-glm(ALF~age+gender+BMI+waist+gc+bc+dy+ac+ht+fht+di+fdi+he+fhe+cf,
+ family=binomial(link = logit),traindata3)#logit全模型
p<-predict(glm1, newdata = testdata, type = "response")
p=exp(p)/(1+exp(p))#计算预测到的概率
问题解决
参考:warning message
本文汇总了R语言中常见的错误及其解决方法,包括导入数据时的数据类型转换问题,RStudio或R安装包受阻,R更新失败,数据筛选错误以及预测值时报错。提供了具体的解决方案,如使用unlist()函数,更换镜像源,修正筛选条件等。
6万+

被折叠的 条评论
为什么被折叠?



