データは次のとおりです。例1:完了
complete <- c("A", "B", "C","J", "C1", "L", "J2", "D", "M", "N")
lst1 <- c(NA, NA, NA, "A", "N", NA,"A", "C", "D", NA )
lst2 <- c(NA, NA, NA,"A", "L", NA, "C1", "J2", "J2", "B")
datf <- data.frame (complete, lst1, lst2, stringsAsFactors = FALSE)
例2:不完全で重複している
complete <- c("A", "B", "C","J", "C1", "L", "C", "D", "M", "N")
lst1 <- c(NA, NA, NA, "A", "N", NA,"A", "C", "D1", NA )
lst2 <- c(NA, NA, NA,"A", "L", NA, "C1", "J2", "J2", "B2")
datf2 <- data.frame (complete, lst1, lst2, stringsAsFactors = FALSE)
私はチェックしたい:(1)lst1とlst2のメンバーが少なくとも一度は完全に存在するかどうか。存在しない場合、停止メッセージはこれが「?」であることを示します。lst1またはlst2(正しいものは何でも)に存在しますが、完全ではありません。私の裁判:例えば1
if (datf$lst1 %in% datf$complete | datf$lst2 %in% datf$complete) {
stop ("the subject in lst1 or lst2 must be complete list ")} else {
cat("I am fine")
}
I am fineWarning message:
In if (datf$lst1 %in% datf$complete | datf$lst2 %in% datf$complete) { :
the condition has length > 1 and only the first element will be used
このエラーメッセージが表示されるのはなぜですか。また、どのように抑制できますか?
Example 2:
if (datf2$lst1 %in% datf2$complete | datf2$lst2 %in% datf2$complete) {
stop ("the subject in lst1 or lst2 must be complete list ")} else {
cat("I am fine")
}
Although there is potential errors the error message is same:
I am fineWarning message:
In if (datf2$lst1 %in% datf2$complete | datf2$lst2 %in% datf2$complete) { :
the condition has length > 1 and only the first element will be used
エラーメッセージの一部として一致しない名前を提供する方法もあります。
(2)コンプリートのメンバーが重複している場合。
編集:
Expected answer:
Example1 <- all members of lst1 and lst2 are also member of complete
expacted message here is "I am fine"
Example2 <-
B2, J2, is member of lst2 but not complete, D1 is member of lst1 but not complete.
complete have two C, so C is duplicated.
The function will stop and print a message
"B2 and J2 are member of lst1, but not in complete
D1 is member of lst2, but not in complete,
check completeness"
"C is duplicated in complete"