rduplication

R duplicate ID variables with different values


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).


Solution

  • you can try

    x[!duplicated(x$user_id), ]
      user_id    location
    1       1    New_York
    3       2     Atlanta
    4       3 San_Antonio