R: NA Issue with checking if all elements in column are the same

106 Views Asked by At

There are several threads asking how to check if all elements in a vector are the same. That is not my issue.

I have been using the all function in R with no issues. I wanted to assess if all elements of a column mydataframe$colA are the same as in mydataframe$colB:

if(all(mydataframe$colA == mydataframe$colB) == FALSE) {...}

However today I started to see NA as being returned as result of the all function, instead of a boolean. I have tried other ways to find if all elements are the same or not. For example:

table(mydataframe$colA == mydataframe$colB) gives me only TRUE

So indeed all my values from column A are the same as the ones in column B.

What can be wrong here? I stress that my script has been working fine, and even today I ran these same lines 8 times before with data from different samples with no problem. All data and all samples are supposed to be in the exact same format of each other.

Thanks in advance!

0

There are 0 best solutions below