R/subset_allelic.R

Defines functions subset_allelic

Documented in subset_allelic

#' @title subset allelic
#' @description A function that returns multi-allelic SNPs.
#' @param df data.frame or data.table
#' @param col.set.uniq column number that should be used to check for uniqness
#' @param how a string that must be either 'multi' or 'bi'
#' @param return.everything should the whole data.frame be returned?
#' @export


subset_allelic <- function(df, col.set.uniq = 1, return.everything = TRUE, how = 'MULTI'){

  what=NULL
  df = setDT(df)
  how = tolower(how)
  tbl = sort(table(df[,..col.set.uniq]))
  if (how == 'multi') {result = names(tbl)[tbl>1]}
  else if (how == 'bi') {result = names(tbl)[tbl==1]}
  else stop(paste('only MULTI or BI allowed'))

  if (return.everything){
    return(df[df[[col.set.uniq]] %in% result,])
  } else {
    return(df[df[[col.set.uniq]] %in% result,..col.set.uniq])
  }

}
frhl/our documentation built on Feb. 5, 2021, 7:30 p.m.