I am trying to count and print the cases in which the values in second and third columns of my dataframe named 'DATA'. But I have "missing value where TRUE/FALSE needed" Error.
Could you help me please? How can I write my condition in if statement without getting this error?
My Code:
deneme<-function(id=vector()){
i<-1
counter<-1
sulfate<-DATA[,2]
nitrate<-DATA[,3]
while (DATA[i,4] == DATA[i+1,4]){
if(DATA[i,2] != NA & DATA[i,3] != NA){
counter<-counter+1
}
i<-i+1
}
print(counter)
}
when
DATA[i,2]
isNA
, the comparison is alsoNA
:You need to use function
is.na
to test wether you haveNA
value:Hence, you should change your line of code to: