Data examples
df = structure(list(class = structure(c(4L, 1L, 1L, 3L, 2L), .Label = c("apple",
"berry", "grape", "orange"), class = "factor"), value = c(NA,
NA, 1, 1, NA)), .Names = c("class", "value"), row.names = c(NA,
-5L), class = "data.frame")
looks like
class value
1 orange NA
2 apple NA
3 apple 1
4 grape 1
5 berry NA
How to delete a row with NA in a group only if the group has a different non NA value
desired output
class value
1 orange NA
2 apple 1
3 grape 1
4 berry NA
This can be done in three steps using a subset and a merge. I'm interested in the approachdata.table
source
share