我有一個數據幀(稱爲hp),其中包含更多與NA-s的列。這些列的類是因子。首先,我想將其改爲人物,用「無」填充NA-s並將其改回因子。我有14列,因爲它我想用循環。但它不起作用。在數據幀中更改NA-s更多列
Thx尋求幫助。
列:
miss_names<-c("Alley","MasVnrType","FireplaceQu","PoolQC","Fence","MiscFeature","GarageFinish", "GarageQual","GarageCond","BsmtQual","BsmtCond","BsmtExposure","BsmtFinType1",
"BsmtFinType2","Electrical")
循環:
for (i in miss_names){
hp[i]<-as.character(hp[i])
hp[i][is.na(hp[i])]<-"NONE"
hp[i]<-as.factor(hp[i])
print(hp[i])
}
Error in sort.list(y) : 'x' must be atomic for 'sort.list'
Have you called 'sort' on a list?
請提供一個可重現的例子。添加幾行hp對象,理想情況下使用'dput'。 http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example –