Skip to content
Prev 367180 / 398506 Next

Is a list an atomic object? (or is there an issue with the help page of ?tapply ?)

You could also call this "interesting example" a bug.

Clearly not enough code reuse in the implementation of tapply().
Instead of the current 25 lines of code, it could be a simple
wrapper around split() and sapply() e.g.. something like:

   tapply2 <- function(X, INDEX, FUN=NULL, ..., simplify=TRUE)
   {
     f <- make_factor_from_INDEX(INDEX)  # same as tapply(INDEX=INDEX, 
FUN=NULL)
     sapply(split(X, f), FUN, ..., simplify=simplify, USE.NAMES=FALSE)
   }

and then be guaranteed to behave consistently with split() and
sapply(). Also the make_factor_from_INDEX() step maybe could be
shared with what aggregate.data.frame() does internally with its
'by' argument.

Still a mystery to me why the power of code sharing/reuse is so
often underestimated :-/

H.
On 02/15/2017 11:32 AM, Hadley Wickham wrote: