Skip to content
Prev 176260 / 398503 Next

SUM,COUNT,AVG

calpeda:
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