I have a data frame in R that is supposed to have duplicates. However, there are some duplicates that I would need to remove. In particular, I only want to
You could also try
df[c(diff(as.numeric(df$x)), 1) != 0, ]
In case x is of character class (rather than factor), try
x
character
factor
df[c(diff(as.numeric(factor(df$x))), 1) != 0, ] # x y # 1 A 1 # 2 B 2 # 3 C 3 # 4 A 4 # 5 B 5 # 6 C 6 # 7 A 7 # 9 B 9 # 10 C 10