R/matrixUtils.R

Defines functions i2c c2i i2col utri

Documented in c2i i2c i2col utri

i2c <- function
### Index to coordinates
(nrows, ##<< number of rows in the matrix
 i      ##<< the index into the matrix
 ) {
  y <- ceiling(i/nrows)
  x <- i%%nrows
  if (x == 0) {x <- nrows}
  c(x,y)
### the row col coordinates into the matrix
}

c2i <- function
### coordinates to index
(nrows, ##<< number of rows in the matrix
 x,     ##<< the row coordinate
 y      ##<< the col coordinate
 ) {
  (y-1) * nrows + x
### the index into the matrix
}
  
i2col <- function
### index to column
(nrows, ##<< number of rows in matrix
 i      ##<< the index
 ) {
  y <- ceiling(i/nrows)
### returns the column of the matrix
}

utri <- function
### The upper triangle of a matrix
(mat  ##<< A matrix
 ){
  mat[upper.tri(mat)]
  ### Returns a vector
}
  

Try the ProCoNA package in your browser

Any scripts or data that you put into this service are public.

ProCoNA documentation built on Nov. 1, 2018, 3:28 a.m.