Q:

R: Counting observations of a class

I have following dataset:
X v1 v2  class
1 12 10  A
2 11 13  B
3 14 15  A

I have two objects of class A and one Object of class B. What I need to do is to take this matrix and delete all classes whose number of observations do not meet a threshold-requirement. If my Threshold-Count = 2, I would like to have following result:
X v1 v2  class
1 12 10  A
3 14 15  A

How could I achieve this in R?

A:

You can use table for example:
tt <- table(dat$class)
dat[dat$class %in% names(tt[tt==threshold ]),]

For example:
dat <- read.table(text='X v1 v2  class
1 12 10  A
2 11 13  B
3 14 15  A',header=TRUE)

threshold <- 2
tt <- table(dat$class)
dat[dat$class %in% names(tt[tt==threshold]),]

