[R] use of class variable in r as in Proc means of sas

Girish A.R. garamach at gmail.com
Wed Sep 23 08:43:18 CEST 2009


Here's the code that does the job for quartiles (0,25,50,75,100). To get to
your objective of (5,10,25,75,90) is left as an exercise. There are several
well-written introductory books in R, in addition to the freely available
presentations and other online resources. I think you should spend some time
going thru' them.
----------------------
library(doBy)
Lines <- "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" 
DF <- read.table(con<- textConnection(Lines), skip = 1)
close(con)
names(DF) <- scan(textConnection(Lines), what = "", nlines = 1) 
qfun <- function(x, digits=3,sci=F,...){
  c(q=quantile(x, ...))
}
summaryBy(price~zip,data=DF,FUN=qfun,na.rm=TRUE)
--------------------------------------

cheers,
-Girish

===========================

premmad 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 is 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-tp25530654p25530997.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list