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

Collapse All | Expand All

(-)tapply.R (-3 / +11 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
    if (allg <- ngroup <= 1000L) {
40
    levels(group) <- as.character(seq_len(ngroup))
41
    levels(group) <- as.character(seq_len(ngroup))
41
    class(group) <- "factor"
42
    class(group) <- "factor"
43
    }
42
    ans <- split(X, group) # use generic, e.g. for 'Date'
44
    ans <- split(X, group) # use generic, e.g. for 'Date'
45
    if (allg) {
46
    names(ans) <- NULL
47
    group <- as.logical(lengths(ans))  # index; equivalently, lengths(ans) > 0L
48
    ans <- ans[group]
49
    } else {
50
    group <- as.integer(names(ans))
43
    names(ans) <- NULL
51
    names(ans) <- NULL
44
    index <- as.logical(lengths(ans))  # equivalently, lengths(ans) > 0L
52
    }
45
    ans <- lapply(X = ans[index], FUN = FUN, ...)
53
    ans <- lapply(X = ans, FUN = FUN, ...)
46
    if (simplify && all(lengths(ans) == 1L)) {
54
    if (simplify && all(lengths(ans) == 1L)) {
47
	ansmat <- array(dim = extent, dimnames = namelist)
55
	ansmat <- array(dim = extent, dimnames = namelist)
48
	ans <- unlist(ans, recursive = FALSE)
56
	ans <- unlist(ans, recursive = FALSE)
Lines 51-57 Link Here
51
			dim = extent, dimnames = namelist)
59
			dim = extent, dimnames = namelist)
52
    }
60
    }
53
    if(length(ans)) {
61
    if(length(ans)) {
54
	ansmat[index] <- ans
62
	ansmat[group] <- ans
55
    }
63
    }
56
    ansmat
64
    ansmat
57
}
65
}

Return to bug 16640