Skip to content

Instantly share code, notes, and snippets.

@narath
Created July 29, 2019 20:42
Show Gist options
  • Save narath/7234fc91157a77c08580fd5747f1f07a to your computer and use it in GitHub Desktop.
Save narath/7234fc91157a77c08580fd5747f1f07a to your computer and use it in GitHub Desktop.
R: keep only the first row for duplicate data

How to keep only the first instance of a row

Derived from this helpful stackoverflow answer

dup_data %>% 
  group_by(MRN) %>%
  filter(Year == min(Year)) %>%
  slice(1) %>%
  ungroup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment