Remove duplicated rows

前端 未结 11 1751
清酒与你
清酒与你 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:35

    With sqldf:

    # Example by Mehdi Nellen
    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)
    

    Solution:

     library(sqldf)
        sqldf('SELECT DISTINCT * FROM df')
    

    Output:

      a b
    1 A 1
    2 A 2
    3 B 4
    4 B 1
    5 C 2
    

提交回复
热议问题