View | Details | Raw Unified | Return to bug 16640 | Differences between
and this patch

Collapse All | Expand All

(-)tapply.R (-3 / +5 lines)
Lines 37-48 Link Here
37
        for (i in 2L:nI)
37
        for (i in 2L:nI)
38
           group <- group + cumextent[i - 1L] * (as.integer(INDEX[[i]]) - 1L)
38
           group <- group + cumextent[i - 1L] * (as.integer(INDEX[[i]]) - 1L)
39
    if (is.null(FUN)) return(group)
39
    if (is.null(FUN)) return(group)
40
    index <- logical(ngroup)
41
    index[group] <- TRUE
42
    if (all(index)) {
40
    levels(group) <- as.character(seq_len(ngroup))
43
    levels(group) <- as.character(seq_len(ngroup))
41
    class(group) <- "factor"
44
    class(group) <- "factor"
42
    ans <- split(X, group) # use generic, e.g. for 'Date'
45
    }
46
    ans <- lapply(X = split(X, group), FUN = FUN, ...) # use generic, e.g. for 'Date'
43
    names(ans) <- NULL
47
    names(ans) <- NULL
44
    index <- as.logical(lengths(ans))  # equivalently, lengths(ans) > 0L
45
    ans <- lapply(X = ans[index], FUN = FUN, ...)
46
    if (simplify && all(lengths(ans) == 1L)) {
48
    if (simplify && all(lengths(ans) == 1L)) {
47
	ansmat <- array(dim = extent, dimnames = namelist)
49
	ansmat <- array(dim = extent, dimnames = namelist)
48
	ans <- unlist(ans, recursive = FALSE)
50
	ans <- unlist(ans, recursive = FALSE)

Return to bug 16640