File: makeCompMat.R

package info (click to toggle)
r-cran-multidimbio 1.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 336 kB
  • sloc: makefile: 2
file content (42 lines) | stat: -rw-r--r-- 1,108 bytes parent folder | download
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
36
37
38
39
40
41
42
#' A function to create a pairwise comparison matrix
#' 
#' This function creates a pairwise comparison matrix for n groups.  All
#' possible pairwise combinations are created, with rows in the matrix equal to
#' the desired comparison.
#' 
#' 
#' @param ng A single number indicating the total number of unique groups
#' @return Returns a matrix with two columns and ng choose 2 rows.
#' @seealso \code{\link{PermuteLDA}}
#' @examples
#' 
#' makeCompMat(3)
#' 
#' makeCompMat(4)
#' 
#' data(Groups)
#' NGroups<-length(unique(Groups))
#' 
#' makeCompMat(NGroups)
#' 
#' @export makeCompMat
makeCompMat <- function(ng) {
    comparisons <- c()
    for (i in 1:ng) {
        c.i <- numeric(0)
        for (j in i:ng) {
            c.j <- c(i, j)
            if ((i - j) == 0) {
                next
            } else {
                c.i <- c(c.i, c.j)
            }  #end if/else i-j == 0
        }  #end for j in i:ng
        comparisons <- c(comparisons, c.i)
    }  #end for i in 1:ng
    
    compare <- matrix(comparisons, ncol = 2, byrow = TRUE)
    
    return(compare)
}  #end function makeCompMat