Defines functions highestSDselector

Documented in highestSDselector

#' Select the most variable feature mapping to the same gene.
#' This function allows for a selection of most variable feature from a set of features representing the same entity and collapses redundant matrix into non-redundant matrix.
#' @param df Data frame. Make sure row names are named after the features while the redundant vector (of character type) of the entities that these feature represent is in the first column (i.e. df[,1]).
#' @param vectorOfEntities A non-redundant character vector of the entities we wish to collapse the (rows of) matrix into.
#' @author Alexander Kheirallah ([email protected]) 
#' @export

highestSDselector<- function(df,vectorOfEntities){
  out <- matrix(0, nrow= 1, ncol= ncol(df))
  colnames(out) <- colnames(df)
  St.dev <- apply(X = df[,2:ncol(df)],MARGIN = 1,FUN = sd)
  df <- cbind(df,St.dev)
  for (i in 1:length(vectorOfEntities)) {
    temp <- df[which(vectorOfEntities[i]==df[,1]),]
    out <- rbind(out, temp[which.max(temp$St.dev),1:(ncol(temp)-1)])
  out <- out[-1,]
msxakk89/dat documentation built on April 3, 2020, 5:39 p.m.