[R] by function ??

L.A. romsa at millect.com
Sat Dec 12 21:38:54 CET 2009



Thanks for all the help, They all worked, But I'm stuck again.
I've tried searching, but I not sure how to word my search as nothing came
up.
Here is my new hurdle, my data has 7 abservations and my results have 2
answers:


Here is my data	

     LEAID     ratio  
3 6307     0.7200000
1 6307     0.7623810
2 6307     0.8600000
4 6307     0.9200000
5 8300     0.5678462
7 8300     0.7700000
6 8300     0.8300000


> median<-summaryBy(ratio ~ LEAID, data = Dataset, FUN = median)

> print(median)
  LEAID       ratio.median
1 6307        0.8111905
2 8300        0.7700000

Now what I want is a way to compute 
abs(ratio- median)by LEAID for each observation to produce something like
this

LEAID     ratio          abs
3 6307     0.7200000     .0912
1 6307     0.7623810     .0488
2 6307     0.8600000     .0488 
4 6307     0.9200000     .1088 
5 8300     0.5678462     .2022 
7 8300     0.7700000     .0000 
6 8300     0.8300000     .0600
 
Thanks,
L.A.




Ista Zahn wrote:
> 
> Hi,
> I think you want
> 
> by(TestData[ , "RATIO"], LEAID, median)
> 
> -Ista
> 
> On Tue, Dec 8, 2009 at 8:36 PM, L.A. <romsa at millect.com> wrote:
>>
>> I'm just learning and this is probably very simple, but I'm stuck.
>>   I'm trying to understand the by().
>> This works.
>> by(TestData, LEAID, summary)
>>
>> But, This doesn't.
>>
>> by(TestData, LEAID, median(RATIO))
>>
>>
>> ERROR: could not find function "FUN"
>>
>> HELP!
>> Thanks,
>> LA
>> --
>> View this message in context:
>> http://n4.nabble.com/by-function-tp955789p955789.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> R-help at 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.
>>
> 
> 
> 
> -- 
> Ista Zahn
> Graduate student
> University of Rochester
> Department of Clinical and Social Psychology
> http://yourpsyche.org
> 
> ______________________________________________
> R-help at 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.
> 
> 

-- 
View this message in context: http://n4.nabble.com/by-function-tp955789p962666.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list