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

Collapse All | Expand All

(-)tapply.R (-13 / +9 lines)
Lines 20-42 Link Here
20
{
20
{
21
    FUN <- if (!is.null(FUN)) match.fun(FUN)
21
    FUN <- if (!is.null(FUN)) match.fun(FUN)
22
    if (!is.list(INDEX)) INDEX <- list(INDEX)
22
    if (!is.list(INDEX)) INDEX <- list(INDEX)
23
    INDEX <- lapply(INDEX, as.factor)
23
    nI <- length(INDEX)
24
    nI <- length(INDEX)
24
    if (!nI) stop("'INDEX' is of length zero")
25
    if (!nI) stop("'INDEX' is of length zero")
25
    namelist <- vector("list", nI)
26
    namelist <- lapply(INDEX, levels)
26
    names(namelist) <- names(INDEX)
27
    extent <- lengths(namelist, use.names = FALSE)
27
    extent <- integer(nI)
28
    nx <- length(X)
28
    nx <- length(X)
29
    one <- 1L
29
    if (!all(lengths(INDEX) == nx))
30
    group <- rep.int(one, nx) #- to contain the splitting vector
30
        stop("arguments must have same length")
31
    ngroup <- one
31
    group <- rep.int(1L, nx) #- to contain the splitting vector
32
    ngroup <- 1L
32
    for (i in seq_along(INDEX)) {
33
    for (i in seq_along(INDEX)) {
33
	index <- as.factor(INDEX[[i]])
34
	group <- group + ngroup * (as.integer(INDEX[[i]]) - 1L)
34
	if (length(index) != nx)
35
	ngroup <- ngroup * extent[i]
35
	    stop("arguments must have same length")
36
	namelist[[i]] <- levels(index)#- all of them, yes !
37
	extent[i] <- nlevels(index)
38
	group <- group + ngroup * (as.integer(index) - one)
39
	ngroup <- ngroup * nlevels(index)
40
    }
36
    }
41
    if (is.null(FUN)) return(group)
37
    if (is.null(FUN)) return(group)
42
    ans <- lapply(X = split(X, group), FUN = FUN, ...)
38
    ans <- lapply(X = split(X, group), FUN = FUN, ...)

Return to bug 16640