You can try something like:
library(data.table)
mydata[, ind := all(2000:2003 %in% year), id][(ind)]
# id year sales profit ind
# 1: A 2000 2000 200 TRUE
# 2: A 2001 2050 245 TRUE
# 3: A 2002 2100 290 TRUE
# 4: A 2003 2150 335 TRUE
# 5: B 2000 2200 380 TRUE
# 6: B 2001 2250 425 TRUE
# 7: B 2002 2300 470 TRUE
# 8: B 2003 2350 515 TRUE
With "tidyverse":
library(tidyverse)
mydata %>%
group_by(id) %>%
filter(all(2000:2003 %in% year))
( ):
mydata <- structure(list(id = c("A", "A", "A", "A", "B", "B", "B", "B",
"C", "C", "C", "D", "D"), year = c(2000L, 2001L, 2002L, 2003L,
2000L, 2001L, 2002L, 2003L, 2000L, 2002L, 2003L, 2000L, 2001L
), sales = c(2000L, 2050L, 2100L, 2150L, 2200L, 2250L, 2300L,
2350L, 2400L, 2500L, 2550L, 2600L, 2650L), profit = c(200L, 245L,
290L, 335L, 380L, 425L, 470L, 515L, 560L, 650L, 695L, 740L, 785L
)), .Names = c("id", "year", "sales", "profit"), row.names = c(NA,
13L), class = c("data.table", "data.frame"))