I have a data frame and it looks something like the first df below. Theres duplicates in col1 but not col2. I want to remove all of the duplicate rows except the first row so that it looks like the second df below.
col1 | col2 |
---|---|
x | 1 |
x | 2 |
x | 3 |
y | 1 |
y | 2 |
y | 3 |
col1 | col2 |
---|---|
x | 1 |
y | 1 |
I tried this but it didn't work:
df %>% group_by(col1) %>% filter(duplicated(col1) | n()!=1)