Find out if column in R table includes duplicate values?
duplicates, r
Solution
Check out the `duplicated` function:
duplicated(dat$var1) # the rows of dat var1 duplicated
Documentation is here.
You should also look at the `unique` function.
Problem
I've got a lovely dataframe, my very first, and I'm starting to get the hang of R. One thing I haven't been able to find is a test for duplicate values. I have one column that I'm pretty sure is all unique values, but I don't know that. Is there a way I can ask? For simplicity, let's pretend this is my data: ``` var1 var2 var3 1 1 A 1 2 2 B 3 3 3 C NA 4 4 D NA 5 5 E 4 ``` and I want to know whether `var1` ever repeats.