I have a data frame that I want to remove duplicates that are consecutive (in base). I know rle may be helpful here but can\'t think of how to use it. The exa
rle
Using rle I came up with this
ind <- cumsum(rle(as.character(dat$v1))$length) dat[ind, ]
ind indicates either the first or the last of consecutive entries.
ind
EDIT:
A simple solution to Matthews comment would be
dat[15, 2] <- "May" dat[cumsum(rle(paste0(dat$v1, dat$v2))$length), ]