I have a duplicate date which I want to remove based on the value of another variable. If one of dmean values for corresponding duplicates dates is NA I want to drop it. If both dmean values for a certain date are NA I would like to keep any of the date. Sample data is found below: I have tried
subset(df1, !duplicated(date))
but this removed all duplicates regardless of the value of dmean. For example for date 2010-12-23 I would like to keep the the dmean value 28.38250 instead of the one with NA.
structure(list(date = c("2010-12-22", "2010-12-22", "2010-12-23",
"2010-12-23", "2010-12-24", "2010-12-24", "2010-12-25", "2010-12-25",
"2010-12-26", "2010-12-26", "2010-12-27", "2010-12-27", "2010-12-28",
"2010-12-28"), dmean = c(NA, NA, NA, 28.3825, 35.54625, NA, 75.27625,
NA, NA, 75.225, NA, 41.75, NA, 37.98375)), .Names = c("date",
"dmean"), class = "data.frame", row.names = c(NA, -14L))