Remove duplicated rows

前端 未结 11 1742
清酒与你
清酒与你 2020-11-22 00:00

I have read a CSV file into an R data.frame. Some of the rows have the same element in one of the columns. I would like to remove rows that are duplicates in th

11条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 00:43

    Here's a very simple, fast dplyr/tidy solution:

    Remove rows that are entirely the same:

    library(dplyr)
    iris %>% 
      distinct(.keep_all = TRUE)
    

    Remove rows that are the same only in certain columns:

    iris %>% 
      distinct(Sepal.Length, Sepal.Width, .keep_all = TRUE)
    
    

提交回复
热议问题