Deleting rows that are duplicated in one column based on the conditions of another column

前端 未结 5 632
我在风中等你
我在风中等你 2020-12-13 13:46

Here is an example of my data set;

Date      Time(GMT)Depth Temp  Salinity Density Phosphate
24/06/2002  1000    1           33.855          0.01
24/06/2002          


        
5条回答
  •  长情又很酷
    2020-12-13 13:53

    Introducing a data.table solution which will be the fastest way to solve this (assuming data is your data set)

    library(data.table)
    unique(setDT(data)[order(Date, -Depth)], by = "Date")
    

    Just another way:

    setDT(data)[data[, .I[which.max(Depth)], by=Date]$V1]
    

提交回复
热议问题