0

Considering the sample dataframe as:

df <- data.frame(a=c(rep(1,4),4,7,8), b=c(rep(4,4),6,8,3), 
                 c=c(rep("hey",4),"hi","hello","salam"), 
                 d=c("q","r","g","y","d","e","y"), e=c(2,6,43,56,6,23,4))

I want to remove the rows that are the same for columns a, b, c. The desired output would be three rows as

    a b     c     d   e
1   1 4    hey    q   2 
5   4 6    hi     d   6
6   7 8   hello   e   23
7   8 3   salam   y   4
Maral Dorri
  • 468
  • 5
  • 17

2 Answers2

1

I think you forgot the first row

df[!duplicated(df[,c("a","b","c")]),]

  a b     c d  e
1 1 4   hey q  2
5 4 6    hi d  6
6 7 8 hello e 23
7 8 3 salam y  4
user2974951
  • 9,535
  • 1
  • 17
  • 24
1

dplyr solution is:

library(dplyr)
df %>% distinct(a, b, c, .keep_all = TRUE)
nyk
  • 670
  • 5
  • 11