Q:

Printing only certain panels in R lattice

I am plotting a quantile-quantile plot for a certain data that I have. I would like to print only certain panels that satisfy a condition that I put in for panel.qq(x,y,...). 
Let me give you an example. The following is my code,
qq(y ~ x|cond,data=test.df,panel=function(x,y,subscripts,...){
    if(length(unique(test.df[subscripts,2])) > 3 ){panel.qq(x,y,subscripts,...})})

Here y is the factor and x is the variable that will be plotted on X and y axis. Cond is the conditioning variable. What I would like is, only those panels be printed that pass the condition in the panel function, which is
if(length(unique(test.df[subscripts,2])) > 3). 

I hope this information helps. Thanks in advance. 
Added Sample data,
        y      x cond
1       1      6 125
2       2      5 125
3       1      5 125
4       2      6 125
5       1      3 125
6       2      8 125
7       1      8 125
8       2      3 125
9       1      5 125
10      2      6 125
11      1      5 124
12      2      6 124
13      1      6 124
14      2      5 124
15      1      5 124
16      2      6 124
17      1      4 124
18      2      7 124
19      1      0 123
20      2     11 123
21      1      0 123
22      2     11 123
23      1      0 123
24      2     11 123
25      1      0 123
26      2     11 123
27      1      0 123
28      2      2 123 

So this is the sample data. What I would like is to not have a panel for 123 as the number of unique values for 123 is 3, while for others its 4. Thanks again. 

A:

Yeah, I think it is a subset problem, not a lattice one.  You don't include an example, but it looks like you want to keep only rows where there are more than 3 rows for each value of whatever is in column 2 of your data frame.  If so, here is a data.table solution.
library(data.table)
test.dt <- as.data.table(test.df)
test.dt.subset <- test.dt[,N:=.N,by=c2][N>3]

Where c2 is that variable in the second column.  The last line of code  first adds a variable, N, for the count of rows (.N) for each value of c2, then subsets for N>3.
UPDATE: And since a data table is also a data frame, you can use test.dt.subset directly as the data source in the call to qq (or other lattice function).
UPDATE 2: Here is one way to do the same thing without data.table:
d <- data.frame(x=1:15,y=1:15%%2,  # example data frame
       c2=c(1,2,2,3,3,3,4,4,4,4,5,5,5,5,5))

d$N <- 1 # create a column for count
split(d$N,d$c2) <- lapply(split(d$x,d$c2),length) # populate with count
d
d[d$N>3,] # subset

