openplantpathology / Mungbean_PM

A meta-analysis of mungbean powdery mildew control fungicide efficacy trials
https://openplantpathology.github.io/Mungbean_PM/
Creative Commons Zero v1.0 Universal
1 stars 0 forks source link

Matching vectors with NA values #28

Closed PaulMelloy closed 4 years ago

PaulMelloy commented 4 years ago

Throwing a question out there, I am probably missing a rookie error here is there a way in R to specify how NAs are tested when asking if x == y? ie if I want NA == NA to return TRUE is there a base function for that?

I wrote a function same() to handle them how I want the to be handled, but surely this is a problem others have had to? Cheers

adamhsparks commented 4 years ago

I've never tried or run into this, but you're not alone: http://www.cookbook-r.com/Manipulating_data/Comparing_vectors_or_factors_with_NA/

PaulMelloy commented 4 years ago

Wow, The 4 line function in the example you shared is way more efficient than my 27 line function. Although that example I think can't handle a logical test if length(x) = 1 and length(y) > 1. which mine can.

PaulMelloy commented 4 years ago

Nope their function operates the same as mine. I will replace mine with their and add error for vectors which lengths don't match