0
   x l
1  1 a
2  3 b
3  2 c
4  3 b
5  2 c
6  4 d
7  5 f
8  2 c
9  1 a
10 1 a
11 3 b
12 4 d

The above is the input.

The below is the output.

   x l
1  1 a
2  3 b
3  2 c
4  4 d
5  5 f
  1. I know that column l will have the same value for each group_by(x).
  2. l is a string
  • 4
    I think you can just pass the whole data frame to `unique`. – Alexis Jun 20 '19 at 21:13
  • 1
    you can use `distinct` or use `group_by(x) %>% summarise_all(first)` – Jack Brookes Jun 20 '19 at 21:15
  • 1
    distinct or duplicated – BENY Jun 20 '19 at 21:17
  • 2
    Bunch of options: `unique(df)`, `distinct(df)`, `df %>% distinct(x, l)`. `df %>% group_by(x, l) %>% summarize()`, `df %>% group_by(x) %>% summarize(l = first(l))`... many more. There are small differences if other columns are involved, but any of these will work on the example you show. – Gregor Thomas Jun 20 '19 at 21:18
  • 1
    Possible duplicate of [Remove duplicated rows](https://stackoverflow.com/questions/13967063/remove-duplicated-rows) – Shree Jun 21 '19 at 03:54

1 Answers1

0

# Creation of dataset

x <- c(1,3,2,3,2,4,5,2,1,1,3,4)
l<- c("a","b","c","b","c","d","f","c","a","a","b","d")
df <- data.frame(x,l)

# Simply call unique function on your dataframe

dfu <- unique(df)
Boletus
  • 81
  • 6