Мы можем выбрать те группы, в которых нет всех NA
.
Это можно сделать в базе R:
subset(df, !ave(is.na(Temperature), PixelID, FUN = all))
# PixelID Year X Y Temperature
#6 2 2001 70.8 73.5 0.2
#7 2 2002 70.8 73.5 0.4
#8 2 2003 70.8 73.5 NA
#9 2 2004 70.8 73.5 0.5
#10 2 2005 70.8 73.5 0.3
dplyr
library(dplyr)
df %>% group_by(PixelID) %>% filter(!all(is.na(Temperature)))
и data.table
library(data.table)
setDT(df)[, .SD[!all(is.na(Temperature))], PixelID]
данные
df <- structure(list(PixelID = c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L), Year = c(2001L, 2002L, 2003L, 2004L, 2005L, 2001L, 2002L,
2003L, 2004L, 2005L), X = c(70.8, 70.8, 70.8, 70.8, 70.8, 70.8,
70.8, 70.8, 70.8, 70.8), Y = c(73.5, 73.5, 73.5, 73.5, 73.5,
73.5, 73.5, 73.5, 73.5, 73.5), Temperature = c(NA, NA, NA, NA,
NA, 0.2, 0.4, NA, 0.5, 0.3)), class = "data.frame", row.names = c(NA, -10L))