Skip to content
Back to formatted view

Raw Message

Message-ID: <45867778.3050407@biostat.ku.dk>
Date: 2006-12-18T11:11:52Z
From: Peter Dalgaard
Subject: Aggregate with numerous factors
In-Reply-To: <4586738E.4040608@biostat.ku.dk>

Peter Dalgaard wrote:
> Alternatively, rewrite aggregate() and send us a patch ;-)
>
> It is not necessarily all that hard. Here's a rough idea
>
> IX <- as.data.frame(by)
> OO <- do.call(order,IX)
> Y <- x[OO,]
> g <- cumsum(!duplicated(IX))
> FF <- unique(IX)
> cbind(FF, sapply(split(x,g),FUN))
>
> (completely untested, of course, and if it works, it works only for a
> single-column x; otherwise, you need a loop over the columns somehow.
>   
I see two glaring blunders already...

You need IX[OO,] in two places, and split(Y, g) not x

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