It works.

Thank you so much.

Abou



==========================
AbouEl-Makarim Aboueissa, Ph.D.
Assistant Professor of Statistics
Department of Mathematics & Statistics
University of Southern Maine
96 Falmouth Street
P.O. Box 9300
Portland, ME 04104-9300

Tel: (207) 228-8389
Fax: (207) 780-5607
Email: [EMAIL PROTECTED]
          [EMAIL PROTECTED]
Office: 301C Payson Smith


>>> T.K. <[EMAIL PROTECTED]> 3/3/2008 3:25 PM >>>
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
======================================

______________________________________________
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.

Reply via email to