[R] use of class variable in r as in Proc means of sas
jim holtman
jholtman at gmail.com
Tue Sep 22 15:42:24 CEST 2009
Is this what you want:
> x
zip price
1 60000 567000
2 60001 478654
3 60004 485647
4 60001 2783958
5 60005 97845848
6 60006 378383478
7 60002 397895735
8 60001 487587575
9 60002 478848
10 60003 49847874
11 60004 467648
12 60005 567489
13 60006 4776746
14 60004 4843949
> tapply(x$price, x$zip, quantile, prob=c(0,.05,.1,.75,.9))
$`60000`
0% 5% 10% 75% 90%
567000 567000 567000 567000 567000
$`60001`
0% 5% 10% 75% 90%
478654.0 709184.4 939714.8 245185766.5 390626851.6
$`60002`
0% 5% 10% 75% 90%
478848 20349692 40220537 298541513 358154046
$`60003`
0% 5% 10% 75% 90%
49847874 49847874 49847874 49847874 49847874
$`60004`
0% 5% 10% 75% 90%
467648.0 469447.9 471247.8 2664798.0 3972288.6
$`60005`
0% 5% 10% 75% 90%
567489 5431407 10295325 73526258 88118012
$`60006`
0% 5% 10% 75% 90%
4776746 23457083 42137419 284981795 341022805
On Tue, Sep 22, 2009 at 5:51 AM, premmad <mtechprem at gmail.com> wrote:
>
> Hi,everyone i need to calculate quartile values of a variable grouped by the
> other variable .
> same as in aggregate function(only median,mean or functions is possible-i
> think so)
> Could you please help me to achieve the same for other quartile
> values(5,10,25,75,90) as for median using aggregate.
> Thanks in advance.
> data :
> zip price
> 60000 567000
> 60001 478654
> 60004 485647
> 60001 2783958
> 60005 97845848
> 60006 378383478
> 60002 397895735
> 60001 487587575
> 60002 478848
> 60003 49847874
> 60004 467648
> 60005 567489
> 60006 4776746
> 60004 4843949
> what i want i quartile values of price grouped by zip
> --
> View this message in context: http://www.nabble.com/use-of-class-variable-in-r-as-in-Proc-means-of-sas-tp25530654p25530654.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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?
More information about the R-help
mailing list