I want put stop condition inside a function. The condition is that if first and second elements should match perfectly in order and length.
A <- c("A", "B", "C", "D")
B <- A
C <- c("A", "C", "C", "E")
> A == B
[1] TRUE TRUE TRUE TRUE
This is good situation to go forward
> A == C
[1] TRUE FALSE TRUE FALSE
Since there is one false this condition to stop and output that the condition doesnot hold at 2 and 4 th column.
if (A != B) {
stop("error the A and B does not match at column 2 and 4"} else {
cat ("I am fine")
}
Warning message:
In if (A != B) (stop("error 1")) :
the condition has length > 1 and only the first element will be used
Am I missing something obvious ? Also I can output where error positions are ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…