Reputation: 199
library(magrittr)
library(dplyr)
A <- c('X', 'X', 'Y', 'Y')
B <- c('X', 'X', 'Y', 'Z')
sample_df <- data.frame(A, B)
sample_df %>% filter(A!=B)
I would like to select all rows where the values of A and B don't agree (and A and B are factors); the code above throws the error "Error in Ops.factor(A, B) : level sets of factors are different"
Upvotes: 0
Views: 54
Reputation: 7385
Expanding on Gregor's comment:
Using dplyr
:
sample_df %>%
mutate_all(., as.character) %>%
filter(A!=B)
Upvotes: 1