[R] SUM,COUNT,AVG
Karl Ove Hufthammer
Karl.Hufthammer at math.uib.no
Mon Apr 6 16:58:14 CEST 2009
calpeda:
> I need for each (Materiale, tpdv, UM) to find sum,avg and count
> My idea was to aggregate for the 3 parameters ..but I don t know how to
> get the numeric value (SUM,COUNT,AVG) I need.
If I have understood what you’re trying to accomplish, this should work:
$ library(Hmisc)
$ d=read.table("http://www.nabble.com/file/p22905322/ordini2008_ex.txt")
$ sumfun=function(x) c(sum=sum(x), count=length(x), avg=mean(x))
$ with(d, summarize(qta, Materiale, sumfun, stat.name=NULL))
Materiale sum count avg
1 14001850000 10 1 10,0
2 16006080000 2 1 2,0
3 30100300000 1 1 1,0
4 41SD0800000 3 3 1,0
5 44029740000 2 1 2,0
6 60000321000 3 3 1,0
7 60401721000 1 1 1,0
8 60900761000 2 1 2,0
9 70020030000 2 2 1,0
10 70310010000 2 2 1,0
11 70730040018 3 2 1,5
12 71710040014 1 1 1,0
--
Karl Ove Hufthammer
More information about the R-help
mailing list