File: hierParseFormula.R

package info (click to toggle)
r-cran-vegan 2.5-7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,564 kB
  • sloc: ansic: 2,275; fortran: 1,088; sh: 42; makefile: 2
file content (20 lines) | stat: -rw-r--r-- 592 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
`hierParseFormula` <-
    function (formula, data)
{
    lhs <- formula[[2]]
    if (any(attr(terms(formula, data = data), "order") > 1))
        stop("interactions are not allowed")
    lhs <- as.matrix(eval(lhs, environment(formula), parent.frame()))
    formula[[2]] <- NULL
    rhs <- model.frame(formula, data, drop.unused.levels = TRUE)
    rhs[] <- lapply(rhs, function(u) {
        if (!is.factor(u))
            u <- factor(u)
        u
    })
    if (length(rhs) < 2)
        stop("provide at least two-level hierarchy")
    attr(rhs, "terms") <- NULL
    list(lhs=lhs, rhs=rhs)
}