不可解なエラーが発生しています。次の関数を使用して、任意の列にNA観測値を含むデータフレームの行を削除しています
##### removes NA'd rows from a dataFrame
wipeNArows<-function(X){
rowsToDelete<-unique(unlist(apply(apply(X,2,is.na),2,which)))
if (length(rowsToDelete)>0){
return (X[-rowsToDelete,])
}
else{
return (X)
}
}
この関数は正常に機能します。たとえば、再現可能な例は次のとおりです。
testFrame<-data.frame(x=rpois(20,10),y=rpois(20,10),z=rpois(20,10))
rowsToDelete<-sample(1:nrow(testFrame),5,FALSE)
testFrame$x[rowsToDelete]<-NA
testFrame
wipeNArows(testFrame) ### removes the rows where NA is encountered
これで、約2993行を含むデータフレームができました。このデータフレームを関数に渡すと、次のエラーが発生します。
Error in apply(apply(X, 2, is.na), 2, which) :
error in evaluating the argument 'X' in selecting a method for function 'apply': Error in as.matrix.data.frame(X) :
dims [product 14965] do not match the length of object [14974]
回答ありがとうございます、