File: multcompLetters2.R

package info (click to toggle)
r-cran-multcompview 0.1-10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 268 kB
  • sloc: makefile: 2
file content (23 lines) | stat: -rw-r--r-- 710 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"multcompLetters2" <- 
function (formula, x, data, ...) {
  #Convert formula to character, get rid of "~"
  fm <- as.character(formula)
  fm <- fm[-1]
  #Split char vector with ":" as this points an
  #interaction and is not included in the data
  #per se
  fm <- strsplit(fm, ":", fixed = TRUE)
  y.z  <- tapply(data[,fm[[1]]], data[,fm[[2]]], 
    function(x) do.call(mean, list(x=x)))
  oz <- order(y.z, decreasing= T )
  #This is to handle interactions
  if (length(fm[[2]] > 1)) {
    Lvls <- levels(interaction(data[,fm[[2]]], sep = ":"))[oz]
  } else {
    Lvls <- levels(data[,fm[[2]]])[oz]
  }
  value <- vec2mat(x)
  value <- value[Lvls, Lvls]
  multcompLetters(value, ...)
}