You can use the table
function as follows:
subset(df, table(FACTOR)[FACTOR] >= 3)
# FACTOR VALUE
# 1 ANTONIO 5
# 2 ANTONIO 8
# 3 ANTONIO 7
To help you understand, see what these return:
table(df$FACTOR)
table(df$FACTOR)[df$FACTOR]
table(df$FACTOR)[df$FACTOR] >= 3
You could also use the ave
function to compute the number of observations:
subset(df, ave(VALUE, FACTOR, FUN = length) >= 3)
This last method may be a little more flexible if you have multiple factors like you asked in your comment and updated question. You can do:
subset(df, ave(VALUE, NAME, CLASS, COLOR, FUN = length) >= 3)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…