[R] tapply

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Thu Jul 19 18:19:30 CEST 2007


sigalit mangut-leiba wrote:
> I'm sorry for the unfocused questions, i'm new here...
> the output should be:
> class    aps_mean
> 1              na
> 2             11.5
> 3               8
>
> the mean aps of every class, when every id count *once*,  for example: class
> 2, mean= (11+12)/2=11.5
> hope it's clearer.
>   
Much... Get the first record for each individual from (e.g.)

icul.redux <- subset(icul, !duplicated(id))

then use tapply as before using variables from icul.redux. Or in one go

with(
  subset(icul, !duplicated(id)),
  tapply(aps, class, mean, na.rm=TRUE)
)


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