[R] Simple loop
Hadley Wickham
hadley at rice.edu
Sat May 7 17:21:59 CEST 2011
>> Using paste(Site,Prof) when calling ave() is ugly, in that it
>> forces you to consider implementation details that you expect
>> ave() to take care of (how does paste convert various types
>> to strings?). It also courts errors since paste("A B", "C")
>> and paste("A", "B C") give the same result but represent different
>> Site/Prof combinations.
>
> Well, ave() uses interaction(...) and interaction() has a "drop" argument, so
>
>> with(x, ave(H, Site, Prof, drop=TRUE, FUN=function(y)y-min(y)))
> [1] 8 0 51 0 33 22 21 0
I don't understand why this isn't the default.
Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
More information about the R-help
mailing list