The ==
and !=
are elementwise comparison i.e. it compares the 1st value of column1 against the 1st of column2, 2nd against 2nd and so on. If the intention is to returns match from any values in 'column2' with that of 'column1', use %in%
library(dplyr)
df %>%
filter(column1 %in% column2)
The reverse will be to negate (!
)
df %>%
filter(!column1 %in% column2)
Regarding the OP's description However it is returning some values that seem to be equal.
and Both columns are the double data type.
. It is a tricky situation with the columns are double i.e. it would also have to consider precision to make them equal if it is elementwise. As there is no reproducible example, it is only based on assumption. One option is to round
the column values and do the elementwise comparison
df %>%
filter(round(column1, 1) == round(column2, 1))