You don’t need table
for this:
vector <- c(1, 0, 2, 2, 3, 2, 1, 4)
threshold <- 1
Filter(function (elem) length(which(vector == elem)) <= threshold, vector)
# [1] 0 3 4
You can use table
, but then you get the result as character strings rather than numbers. You can convert them back, of course, but it’s somehow less elegant:
tab <- table(vector)
names(tab)[tab <= threshold]
# [1] "0" "3" "4"