An option would be to group by 'S' and filter the rows having all the unique values of the column 'B' %in% 'B'
library(dplyr)
un1 <- unique(df1$B)
df1 %>%
    group_by(S) %>%
    filter(all(un1 %in% B))
# A tibble: 8 x 2
# Groups:   S [2]
#  S         B
#  <fct> <dbl>
#1 a         1
#2 a         2
#3 a         3
#4 a         4
#5 d         1
#6 d         2
#7 d         3
#8 d         4
Or with data.table
library(data.table)
setDT(df1)[, .SD[all(un1 %in% B)], S]
Or using base R
df1[with(df1, ave(B, S, FUN = function(x) all(un1 %in% x)) == 1),]
data
df1 <- data.frame(S = rep(letters[1:4], c(4, 3, 2, 4)),
          B = c(1:4, c(1, 3, 4), 1:2, 1:4))