题项 回归
作者:互联网
newdata<-newdata[newdata$a285<98&newdata$a285>0,]
sum(is.na(newdata$a285)) ##无缺失值
table(newdata$a285)
newdata$never=rep(NA,nrow(newdata))
newdata$seldom=rep(NA,nrow(newdata))
newdata$sometimes=rep(NA,nrow(newdata))
newdata$often=rep(NA,nrow(newdata))
newdata$frequently=rep(NA,nrow(newdata))
for(i in 1:nrow(newdata)){
if(newdata$a285[i]==1) newdata$never[i]=1
else newdata$never[i]=0
if(newdata$a285[i]==2) newdata$seldom[i]=1
else newdata$seldom[i]=0
if(newdata$a285[i]==3) newdata$sometimes[i]=1
else newdata$sometimes[i]=0
if(newdata$a285[i]==4) newdata$often[i]=1
else newdata$often[i]=0
if(newdata$a285[i]==5) newdata$frequently[i]=1
else newdata$frequently[i]=0
}
table(newdata$sometimes)
标签:nrow,rep,NA,回归,else,a285,题项,newdata 来源: https://blog.csdn.net/jdhsjjsjsjsn/article/details/122619157