Skip to content
Prev 138304 / 398506 Next

Help needed in R

Dear ALL:


Please see below. I hope this will make it more clear.

[1,]    1    1
 [2,]    1    1          number of all observations less than 1 with
indicator 1 (including those 1 with indicator 1  but not 1 with
indicator 0)=2 
[3,]    1    0
 [4,]    1    0
 [5,]    1    0
 [6,]    1    0
 [7,]    1    0
 [8,]    1    0
 [9,]    1    0
[10,]    2    1
[11,]    2    1        number of all observations less than 2 with
indicator 1 (including those 2 with indicator 1  but not 2 with
indicator 0)=11
[12,]    2    0
[13,]    2    0
[14,]    2    0
[15,]    2    0
[16,]    3    0
[17,]    3    0
[18,]    3    0
[19,]    3    0
[20,]    3    0
[21,]    3    0
[22,]    3    0
[23,]    3    0
[24,]    4    0
[25,]    4    0
[26,]    4    0
[27,]    4    0
[28,]    4    0
[29,]    5    1
[30,]    5    1
[31,]    5    1
[32,]    5    1
[33,]    5    1   number of all observations less than 5 with indicator
1 (including those 5 with indicator 1  but not 5 with indicator 0)=33
[34,]    5    0
[35,]    6    0
[36,]    6    0
[37,]    8    0
[38,]    9    0
[39,]    9    0
[40,]   10    1
[41,]   10    1
[42,]   10    1
[43,]   10    1  number of all observations less than 10 with indicator
1 (including those 10 with indicator 1  but not 10 with indicator 0)=43
[44,]   12    0
[45,]   14    0
[46,]   15    1     number of all observations less than 15 with
indicator 1 (including those 15 with indicator 1  but not 15 with
indicator 0)=46
[47,]   15    0
[48,]   17    0
[49,]   23    0


How I can write an R code to do this.

Thanks

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
For me is not very clear, but if I understand:

sapply(sort(unique(data[data[,2]==1,1])),
               function(x)sum(data[data[,2]==1 & data[,1] <= x, 1]))

But the output is:
2  6 31 71 86



On 03/03/2008, AbouEl-Makarim Aboueissa <aaboueissa at usm.maine.edu>
wrote:
those 1 with indicator 1  but not 1 with indicator 0) =2
those 2 with indicator 1 but not 2 with indicator 0) =11
those 5 with indicator 1 but not 5 with indicator 0) =33
those 10 with indicator 1 but not 10 with indicator 0) =43
those 15 with indicator 1 but not 15 with indicator 0) =46
column two.
column one.
03/03/2008
below.
1
1
indicator
indicator
column
in
data<-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,
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,
use...{{dropped:8}}
http://www.R-project.org/posting-guide.html