列 (変数) にすべての欠損値 ( NA
、<NA>
) があるかどうか (およびどの!) をチェックする必要がある関数を作成しています。以下は、関数のフラグメントです。
test1 <- data.frame (matrix(c(1,2,3,NA,2,3,NA,NA,2), 3,3))
test2 <- data.frame (matrix(c(1,2,3,NA,NA,NA,NA,NA,2), 3,3))
na.test <- function (data) {
if (colSums(!is.na(data) == 0)){
stop ("The some variable in the dataset has all missing value,
remove the column to proceed")
}
}
na.test (test1)
Warning message:
In if (colSums(!is.na(data) == 0)) { :
the condition has length > 1 and only the first element will be used
Q1:上記のエラーと修正方法はなぜですか?
Q2:NA
リスト (変数の名前または列番号) を出力するなど、すべての列を見つける方法はありますか?