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

Collapse All | Expand All

(-)tapply.R (-4 / +7 lines)
Lines 39-46 Link Here
39
	ngroup <- ngroup * nlevels(index)
39
	ngroup <- ngroup * nlevels(index)
40
    }
40
    }
41
    if (is.null(FUN)) return(group)
41
    if (is.null(FUN)) return(group)
42
    ans <- lapply(X = split(X, group), FUN = FUN, ...)
42
    levels(group) <- as.character(seq_len(ngroup))
43
    index <- as.integer(names(ans))
43
    class(group) <- "factor"
44
    ans <- split(X, group)
45
    names(ans) <- NULL
46
    index <- as.logical(lengths(ans))  # equivalently, lengths(ans) > 0L
47
    ans <- lapply(X = ans[index], FUN = FUN, ...)
44
    if (simplify && all(lengths(ans) == 1L)) {
48
    if (simplify && all(lengths(ans) == 1L)) {
45
	ansmat <- array(dim = extent, dimnames = namelist)
49
	ansmat <- array(dim = extent, dimnames = namelist)
46
	ans <- unlist(ans, recursive = FALSE)
50
	ans <- unlist(ans, recursive = FALSE)
Lines 48-55 Link Here
48
	ansmat <- array(vector("list", prod(extent)),
52
	ansmat <- array(vector("list", prod(extent)),
49
			dim = extent, dimnames = namelist)
53
			dim = extent, dimnames = namelist)
50
    }
54
    }
51
    if(length(index)) {
55
    if(length(ans)) {
52
        names(ans) <- NULL
53
        ansmat[index] <- ans
56
        ansmat[index] <- ans
54
    }
57
    }
55
    ansmat
58
    ansmat

Return to bug 16640