0

How to remove rows which has identical string variable? Here is example data:

data <- data.frame(c("A", "C", "B"),
                     c("A", "B", "C"),
                     stringsAsFactors = FALSE)

head(data)
#   c..A....C....B.. c..A....B....C..
#1                A                A
#2                C                B
#3                B                C

For the output I would like to get this dataframe:

#  c..A....C....B.. c..A....B....C..
#2                C                B
#3                B                C

As you can see in the first row, same A and A are deleted. tidyverse approach preferred.

user438383
  • 5,716
  • 8
  • 28
  • 43
choij
  • 227
  • 1
  • 7

2 Answers2

3
data <- data.frame(x = c("A", "C", "B"),
                   y = c("A", "B", "C"),
                   stringsAsFactors = FALSE)

library(dplyr)

data %>% 
  filter(x != y)

  x y
1 C B
2 B C
Vinícius Félix
  • 8,448
  • 6
  • 16
  • 32
2

Using subset from base R

subset(data, x != y)
akrun
  • 874,273
  • 37
  • 540
  • 662