Remove duplicated rows

For people who have come here to look for a general answer for duplicate row removal, use !duplicated(): a <- c(rep(“A”, 3), rep(“B”, 3), rep(“C”,2)) b <- c(1,1,2,4,1,1,2,2) df <-data.frame(a,b) duplicated(df) [1] FALSE TRUE FALSE FALSE FALSE TRUE FALSE TRUE > df[duplicated(df), ] a b 2 A 1 6 B 1 8 C 2 > … Read more

Finding ALL duplicate rows, including “elements with smaller subscripts”

duplicated has a fromLast argument. The “Example” section of ?duplicated shows you how to use it. Just call duplicated twice, once with fromLast=FALSE and once with fromLast=TRUE and take the rows where either are TRUE. Some late Edit: You didn’t provide a reproducible example, so here’s an illustration kindly contributed by @jbaums vec <- c(“a”, … Read more

tech