0

I have a data frame that looks like this;

head(x)
user_id    location
1          New York
1          Chicago
2          Atlanta
3          San Antonio

I would like to remove the duplicate rows (ie. user_id 1) without regard to their location. So I need a new data frame that only has unique ID's but still has ONE of their locations ( so for ID 1, it doesn't matter if it gets Chicago or New York).

chattrat423
  • 603
  • 2
  • 11
  • 24
  • 2
    `x[!duplicated(x$user_id), ]`... – Cath May 27 '15 at 14:55
  • Can you provide a better code, this code seems already what you are looking for because it has a duplicate row but they belong to different location. Or maybe I miss something, if the case ignore my comment. – SabDeM May 27 '15 at 14:58
  • And you could use `distinct()` from the dplyr package: http://stackoverflow.com/questions/22959635/remove-duplicated-rows-using-dplyr/26302351 – Sam Firke May 27 '15 at 15:23

1 Answers1

2

you can try

x[!duplicated(x$user_id), ]
  user_id    location
1       1    New_York
3       2     Atlanta
4       3 San_Antonio
Mamoun Benghezal
  • 5,264
  • 7
  • 28
  • 33