If you run tapply with the specified function (not NULL), say sum , as in the help, you will see that the result is a two-dimensional array with NA in one cell:
res <- tapply(1:3, ind, sum) res AB 1 1 NA 2 2 3
This means that one combination of factors, namely (1, B), is absent. When FUN is NULL, it returns vector indices corresponding to all combinations of factors. To check this:
> which(!is.na(res)) [1] 1 2 4
It should be noted that this function can return NA, as in the following toy example:
> f <- function(x){ if(x[[1]] == 1) return(NA) return(sum(x)) } > tapply(1:3, ind, f) AB 1 NA NA 2 2 3
Thus, in the general case, NA does not mean that the factor combination is absent.
source share