I'm trying to find a good way to test whether or not the correlation between two vectors is perfect (or NA.) I've tried lots of different methods, but I'm having a similar problem with all of them, namely that the result of correlation doesn't evaluate in the way I'd expect.
This is my latest example:
foo1 <- c(4, NA, 6, NA)
foo2 <- c(1, 2, 3, 4)
set <- c(-1, 1, NA)
correlation <- cor(foo1, foo2, use = "na.or.complete") # Result: 1
correlation %in% set # Should be TRUE, is FALSE
correlation == 1 # Should also be TRUE, but is FALSE
is.numeric(correlation) is TRUE. The only value I can see in it or around it is 1. Then whyyy in the world does this not work?
set <- c('-1', '1', NA)
This works, but I'm not sure why, and I'm worried there are ways that it might fail because I clearly don't understand what's going on with the returned value.
Any insight at all would be helpful!