[R] tapply question

Frank Johannes fjohannes at fastmail.fm
Fri Dec 16 16:44:16 CET 2005


HI,
Suppose I have the following data structure.
           LRT  tp
1   1.50654010 522
2   0.51793929 522
3   0.90340299 522
4   1.20293325 522
5   1.05578774 523
6   0.01617942 523
7   0.68183543 523
8   0.43820244 523
9   1.14123995 524
10  0.05809550 524
11  0.93061597 524
12  1.39739700 524
13  1.05220953 525
14  0.03471461 525
15  0.63168798 525
16  1.40592603 525
17  1.41884492 526
18  0.23388479 526
19  0.21881064 526
20  0.99710830 526
21  2.02054187 527
22  1.99872887 527
23  1.04187450 527
24  1.31556807 527
25  2.77775190 528
26  2.94778561 528
27  1.88800177 528
28  2.08249941 528


I have succesfully used a command line such as the one below to get
maxima for each "tp-category'

data.out<-data[tapply(LRT,tp, function(x) which(LRT==max(x))),]

However, when I try it on the above data, it gives me the following
error message:
>Error in "[.data.frame"(data, tapply(LRT, tp, function(x) which(LRT ==  : 
        invalid subscript type

I don't know what to do.
Thanks for your help

--




More information about the R-help mailing list