[R] Calculate of data frame

Peter Dalgaard p.dalgaard at biostat.ku.dk
Thu Jul 14 19:28:51 CEST 2005


"Zhang, Fan" <fzhang at doubleclick.net> writes:

> Now I want to get the total count and value for each model/date pair,
> like
> model    count    value    date
> A            6        31.8        7/1/2005
> A            3            10.2    7/2/2005
> B            7            14.2    7/1/2005
> B            10            67.4      7/2/2005
>  
> Anyone can tell me how to do this?

> aggregate(df[,c("count","value")],df[,c("date","model")],sum)
      date model count value
1 7/1/2005     A     6  31.8
2 7/2/2005     A     3  10.2
3 7/1/2005     B     7  14.2
4 7/2/2005     B    10  71.4


-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907




More information about the R-help mailing list