filter data frame if two column have same text

I have a data frame with two columns have TRUE and FALSE and i want exclude records having both the columns have true values .

i am trying to apply the same in commented code below any solution ...??

df <- data.frame(column1=c("TRUE",	"FALSE",	"TRUE",	"TRUE",	"TRUE",	"TRUE",	"TRUE",	"TRUE",	"FALSE",	"TRUE"),
                 column2 =c("TRUE",	"FALSE",	"TRUE",	"TRUE",	"TRUE",	"FALSE",	"TRUE",	"TRUE",	"TRUE",	"TRUE"))


  #compare_df <- df1_long %>% 
  #  full_join(df2_long, by=c("Names", "options"), keep = TRUE) %>% 
  # distinct(Names.x, options.x, Names.y, options.y) %>% 
  #arrange(Names.x, Names.y,  options.x, options.y) %>% 
  # mutate(
  #  consistant_names = !is.na(Names.x) & !is.na(Names.y),
  # consistant_options = !is.na(options.x) & !is.na(options.y)
  #) 

required output should be look like

column1 column2
FALSE FALSE
TRUE FALSE
FALSE TRUE
df[!(df$column1 == "TRUE" & df$column2 == "TRUE"), ]

If you define the values as logical TRUE/FALSE, rather than characters, then the answer would be:

df <- data.frame(column1=c(TRUE,	FALSE,	TRUE,	TRUE,	TRUE,	TRUE,	TRUE,	TRUE,	FALSE,	TRUE),
                 column2 =c(TRUE,	FALSE,	TRUE,	TRUE,	TRUE,	FALSE,	TRUE,	TRUE,	TRUE,	TRUE))

df[!(df$column1 & df$column2), ]
1 Like

Thanks for the response
how can i add here in my code...??

compare_df <- df1_long %>%
full_join(df2_long, by=c("Names", "options"), keep = TRUE) %>%
distinct(Names.x, options.x, Names.y, options.y) %>%
arrange(Names.x, Names.y, options.x, options.y) %>%
mutate(
consistant_names = !is.na(Names.x) & !is.na(Names.y),
consistant_options = !is.na(options.x) & !is.na(options.y)
)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.