For the following data
ds <- read.table(header = TRUE, text =\" id year attend 1 2007 1 1 2008 1 1 2009 1 1 2010 1 1 2011 1 8 200
Use filter in conjunction with base::ave
filter
base::ave
ds %>% dplyr::filter(ave(!is.na(attend), id, FUN = all))
To obtain
id year attend 1 1 2007 1 2 1 2008 1 3 1 2009 1 4 1 2010 1 5 1 2011 1 6 9 2007 2 7 9 2008 3 8 9 2009 3 9 9 2010 5 10 9 2011 5