This question already has an answer here:
I have a dataframe where I would like to remove all rows with duplicates. For instance my dataframe looks like:
> df <- data.frame(A = c("Happy", "Happy", "Sad", "Confused", "Mad", "Mad"), B = c(1, 2, 3, 4, 5, 6))
> df
A B
1 Happy 1
2 Happy 2
3 Sad 3
4 Confused 4
5 Mad 5
6 Mad 6
I only want rows where the entries in A are unique to get:
A B
1 Sad 3
2 Confused 4
You can try
duplicated
or
or
or
or using
data.table
(similar to @beginneR's use ofave
)or
akrun seems to be collecting different methods, so here's another one in base:
(I guess the one with
duplicated
would be the most commonly used method)Or using dplyr: