#' Classify elements of vector based on one dimension
#'
#' This function classifies samples based on one dimension; e.g. PC1 from PCA
#'
#' @param namedVectorOfValues A numeric vector where elements are named. Elements could be sample names.
#' @param sorted_axis_thresholds Thresholds along the axis on which classification is based.
#' @param classificationNames A character vector, naming the intervals of axis that are detrmined by the thresholds.
#' @return A data frame where elements of namedVectorOfValues are classified
#' @return
classifyBased_on_one_dimension <- function(namedVectorOfValues, sorted_axis_thresholds, classificationNames){
if(!(length(classificationNames)==(length(sorted_axis_thresholds)+1))){
print("'sorted_axis_threshold' :")
print(sorted_axis_thresholds)
print("'classificationNames' :")
print(classificationNames)
stop("The count of categories in the 'classificationNames' does not make sense in light of count of 'PC_axis_threshold'")
}
print("Please make sure that the order of elements in 'classificationNames' agrees with the order of elements in 'PC_axis_thresholds'")
orderedClassificationIndices <- findInterval(x = namedVectorOfValues, vec = sorted_axis_thresholds) + 1
finalClassification <- classificationNames[orderedClassificationIndices]
out <- as.data.frame(cbind(samples_name = names(namedVectorOfValues), finalClassification))
return(out)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.