#' 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.
#' @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)])
print(i)
}
out <- out[-1,]
out
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.