R/maf.R

Defines functions `maf`

`maf` <- function(x) {
  # compute the minor allele frequency for a vector or for each row of a matrix.
  if(is.vector(x)) {
   p <- (x[1]+0.5*x[2])/sum(x)
   y <- min(p,1-p)
  } else
  if(is.matrix(x)) {
   p <- (x[,1]+0.5*x[,2])/apply(x,1,sum)
   y <- pmin(p,1-p)
  }
  return(y)
}

Try the HardyWeinberg package in your browser

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

HardyWeinberg documentation built on May 7, 2022, 5:05 p.m.