R/getColumnQuantiles.R

Defines functions getColumnQuantiles

Documented in getColumnQuantiles

#' Calculate quantile for the columns in a matrix
#' 
#' @param X the matrix
#' @param prob a numeric probablity 
#' @param naRm a boolean, whether to remove NAs
#' @param onlyNonzeroVals a boolean, whether to only include non-zero values
#' @return a vector of quantiles
#' 
#' @examples
#' getColumnQuantiles(matrix(1:25, nrow=5), prob = 0.5)
#' 
#' @concept rcellminer
#' @export
#' 
#' @importFrom stats quantile
getColumnQuantiles <- function(X, prob, naRm=FALSE, onlyNonzeroVals=FALSE){
	colQuantiles <- vector(mode="numeric", length=ncol(X))
	for (j in seq(colQuantiles)){
		if (onlyNonzeroVals){
			selector <- X[,j] != 0
		} else {
			selector <- seq(X[,j])
		}
		colQuantiles[j] <- quantile(x=X[selector,j], probs=prob, na.rm=naRm)
	}
	return(colQuantiles)
}

Try the rcellminer package in your browser

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

rcellminer documentation built on Nov. 26, 2020, 2:02 a.m.