atotal.rdc: Version of atotal in RDC

Usage Arguments Examples

Usage

1
atotal.rdc(arr, FUN = sum, name = "Total", ...)

Arguments

arr
FUN
name
...

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (arr, FUN = sum, name = "Total", ...) 
{
    d <- dim(arr)
    if (length(d) == 1) {
        arr <- c(arr)
        d <- dim(arr)
    }
    if (is.character(FUN)) 
        FUN <- get(FUN, mode = "function")
    else if (mode(FUN) != "function") {
        farg <- substitute(FUN)
        if (mode(farg) == "name") 
            FUN <- get(farg, mode = "function")
        else stop(paste("\"", farg, "\" is not a function", sep = ""))
    }
    if (is.null(d)) {
        ret <- c(arr, FUN(arr))
        names(ret)[length(ret)] = name
        return(ret)
    }
    n <- length(d)
    name <- rep(name, length = n)
    ret <- arr
    ind <- 1:n
    for (i in n:1) {
        new <- apply(ret, ind[-i], FUN, ...)
        ret <- abind(ret, new, i, name[i])
    }
    ret
  }

gmonette/spida15 documentation built on May 17, 2019, 7:26 a.m.