[R] Create variables with common values for each group

Peter Dalgaard p.dalgaard at biostat.ku.dk
Tue Jun 20 12:18:56 CEST 2006


"jim holtman" <jholtman at gmail.com> writes:

> ?ave

Finally, someone remembered it!
 
> > cbind(x, ave(x$h.age, x$hhid))

>        hhid h.age ave(x$h.age, x$hhid)
> 1  10010020    23             23.00000
> 2  10010020    23             23.00000


Or, get rid of ugly colname using 

cbind(x, hhavg=ave(x$h.age, x$hhid))

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