I guess you are looking for the number of rows satisfying the following condition. Assuming that you have a cutoff k = 1, 2, 5, 10, 15 1) x[i,1] < k regardless of the value of x[i,2], OR 2) x[i,1] == k and x[i,2] == 1
Here is my take on this problem. It is not elegant but it seems to do the job. > ## Data > data1 <-matrix(c(2,2,12,2,1,10,10,4,10,1,1,2,2,1,2,10,3,1,1,1,3,5,17,23,9,9,3,3,15,5, + 4,5,5,5,4,8,1,15,3,3,1,6,3,6,3,4,5,14,4, + 0,0,0,0,0,1,1,0,1,1,0,1,1,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,1,1,0,1,1,1,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0),49,2) > > ## Function definition > find.n <- function(cutoff, x=data1){ + x1 <- x[,1] + x2 <- x[,2] + sum(x1 < cutoff | ((x1 == cutoff )& (x2==1))) + } > > ## Use the function > sapply(c(1, 2, 5, 10, 15), find.n) [1] 2 11 33 43 46 -- ====================================== T.K. (Tae-kyun) Kim Ph.D. student Department of Marketing Marshall School of Business University of Southern California ====================================== [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.