データフレーム(hp)にはNA-sを持つ列が何個含まれていますか?これらの列のクラスはfactorです。最初に私はそれを文字に変更し、NA-sに "none"を記入して元に戻します。私は14の列を持っているので、私はループでそれを作りたいと思います。しかし、それは動作しません。データフレームのNA-s個以上の列を変更する
お願いします。
列:
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?
再現可能な例を示してください。理想的には 'dput'を使用してhpオブジェクトのいくつかの行を追加します。 http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example –