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

Collapse All | Expand All

(-)tapply.R (-16 / +12 lines)
Lines 22-43 Link Here
22
    if (!is.list(INDEX)) INDEX <- list(INDEX)
22
    if (!is.list(INDEX)) INDEX <- list(INDEX)
23
    nI <- length(INDEX)
23
    nI <- length(INDEX)
24
    if (!nI) stop("'INDEX' is of length zero")
24
    if (!nI) stop("'INDEX' is of length zero")
25
    namelist <- vector("list", nI)
25
    INDEX <- lapply(INDEX, as.factor)
26
    names(namelist) <- names(INDEX)
26
    if (!all(lengths(INDEX) == length(X)))
27
    extent <- integer(nI)
27
        stop("arguments must have same length")
28
    nx <- length(X)
28
    namelist <- lapply(INDEX, levels)#- all of them, yes !
29
    one <- 1L
29
    extent <- lengths(namelist, use.names = FALSE)
30
    group <- rep.int(one, nx) #- to contain the splitting vector
30
    group <- as.integer(INDEX[[1L]]) #- to contain the splitting vector
31
    ngroup <- one
31
    ngroup <- extent[1L]
32
    for (i in seq_along(INDEX)) {
32
    if (nI > 1L)
33
	index <- as.factor(INDEX[[i]])
33
        for (i in 2L:nI) {
34
	if (length(index) != nx)
34
           group <- group + ngroup * (as.integer(INDEX[[i]]) - 1L)
35
	    stop("arguments must have same length")
35
           ngroup <- ngroup * extent[i]
36
	namelist[[i]] <- levels(index)#- all of them, yes !
36
        }
37
	extent[i] <- nlevels(index)
38
	group <- group + ngroup * (as.integer(index) - one)
39
	ngroup <- ngroup * nlevels(index)
40
    }
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, ...)
43
    index <- as.integer(names(ans))
39
    index <- as.integer(names(ans))

Return to bug 16640