1

I'm trying to extract only the rows when b is unique value per a.

Here is some sample data

a <- c(1,1,2,2,3,3,4,4,5,5,5,6,6,7,7,8,8,9,9,9,9,9,10,10,10)
b <- c(1,2,1,1,5,5,6,1,1,1,3,2,2,1,1,2,3,1,2,3,4,4,1,2,2)
df1 <- data.frame(a, b)

and using the dplyr package

library(dplyr)

Unique <- df1 %>%
  group_by(a) %>%
  filter(n_distinct(b))

The desired output should be a data frame length 18

user08041991
  • 617
  • 8
  • 20

1 Answers1

5

We can try

library(dplyr)
df1 %>%
    distinct()

Or in base R

unique(df1)
akrun
  • 874,273
  • 37
  • 540
  • 662