Reputation:
Say I have a dataset like the one below:
x y z
1 9 3
3 0 3
4 0 2
1 4 1
5 1 9
4 2 3
9 0 1
I would like to to drop / collapse all the rows that are repeated based on the value in column z so that my new data set would read like this:
x y z
1 9 3
4 0 2
1 4 1
5 1 9
Rows 2 and 6 have been dropped because they contained a repeated value in z (the value of 3) I would simply like R to drop all remaining iterations of that whole row.
Upvotes: 1
Views: 63
Reputation: 320
If your data is stored in data frame df
, you could do something like:
df <- df[!duplicated(df$z), ]
Upvotes: 2