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

前端 未结 5 454
我在风中等你
我在风中等你 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 14:10

    # First find the maxvalues
    maxvals = aggregate(df$Depth~df$Date, FUN=max)
    #Now use apply to find the matching rows and separate them out
    out = df[apply(maxvals,1,FUN=function(x) which(paste(df$Date,df$Depth) == paste(x[1],x[2]))),]
    

    Does that work for you?

提交回复
热议问题