Skip to content
Prev 367167 / 398506 Next

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

Right. More precisely the function passed thru the FUN argument must
work on the subsets of X generated internally by tapply(). You can
actually see these subsets by passing the identity function:

   X <- letters[1:10]
   INDEX <- c(rep(1,5),rep(2,5))
   tapply(X, INDEX, FUN=identity)
   # $`1`
   # [1] "a" "b" "c" "d" "e"
   #
   # $`2`
   # [1] "f" "g" "h" "i" "j"

Doing this shows you how tapply() splits the vector-like object X into
a list of subsets. If you replace the identity function with a function
that cannot be applied to these subsets, then you get an error:

   tapply(X, INDEX, FUN=sum)
   # Error in FUN(X[[i]], ...) : invalid 'type' (character) of argument

As you can see, here we get an error even though X is an atomic vector.

H.
On 02/14/2017 05:41 PM, Richard M. Heiberger wrote: