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

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

    This might be not the fastest approach if your data frame is large, but a fairly strightforward one. This might change the order of your data frame and you might need to reorder by e.g. date afterwards. Instead of deleting we split the data by date, in each chunk pick a row with the maximum date and finally join the result back into a data frame

    data = split(data, data$Date)
    data = lapply(data, function(x) x[which.max(x$Depth), , drop=FALSE])
    data = do.call("rbind", data)
    

提交回复
热议问题