# Re: [R] Help needed in R

From: AbouEl-Makarim Aboueissa <aaboueissa_at_usm.maine.edu>
Date: Mon, 03 Mar 2008 15:49:49 -0500

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: aaboueissa_at_usm.maine.edu

aboueiss_at_yahoo.com
Office: 301C Payson Smith

>>> T.K. <taekyunk_at_gmail.com> 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
University of Southern California
======================================

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help