Remove consecutive duplicates from dataframe

后端 未结 3 499
孤城傲影
孤城傲影 2020-12-30 06:36

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

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-30 07:01

    Here's a way, not with rle, but a way none-the-less:

    dat[with(dat, c(TRUE, diff(as.numeric(interaction(v1, v2))) != 0)), ]
    

    This assumes you're using factor columns, as your sample data implies.

提交回复
热议问题