jeudi 23 août 2018

R if both condition satisfied

I need to create a if statement if any of the 2 columns has null/na value, then stop running script. However I have trouble to set the if statement to be Both, so my question is how to set if statement AND condition

Here is an example:

x=data.frame(a=c(1,2,3), b=NA, c=c("re", "de", "oo"))

because column b has na value, the following code any(is.na(x$b))will give a TRUE logic

[1] TRUE

Column C has value, so the following code any(is.na(x$c)) gives a FALSE logic

[1] FALSE

however, when I combine both condition together any(is.na(x$b))&any(is.na(x$c)), the result should be TRUE as col B has na, but the result is actually FALSE, any idea how to write the right code please?

Thank you so much!

Aucun commentaire:

Enregistrer un commentaire