apct: Transform a frequency table to percentages

Usage Arguments Examples

View source: R/fun.R

Usage

1
apct(x, MARGIN = 1)

Arguments

x
MARGIN

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
##---- 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 (x, MARGIN = 1) 
{
    if (length(dim(x)) == 1) {
        ret <- cbind(N = x, pct = 100 * x/sum(x, na.rm = T))
        ret <- rbind(ret, Total = apply(ret, 2, sum, na.rm = T))
        print(round(ret, 1))
        return(invisible(ret))
    }
    ret <- list(N = atotal(x), pct = 100 * acond(x, MARGIN))
    cat("\nN:\n")
    print(ret[[1]])
    cat("\nPercentage:\n")
    print(round(ret[[2]], 1))
    invisible(ret)
  }

gmonette/spida documentation built on May 17, 2019, 7:25 a.m.