nz_median: Non-zero median of data frames, matrices or vectors

Description Usage Arguments Value Examples

View source: R/functions.R

Description

Calculate non zero median of a data frame, matrix or vector. If the parameter by is applied, median will be calculated per groups of columns, not rows.

Usage

1

Arguments

x

a numerical vector, matrix or data frame.

by

a vector or list of grouping elements, each as long as the variables in the data frame x. The elements are coerced to factors before use.

Value

Non zero median of x or non zero median of groups of columns in x.

Examples

1
2
3
4
5
6
vector_test <- c(rep(0,10),1:100)
nz_median(vector_test)
matrix_test <- matrix(c(rep(0,10),1:100),nrow=10)
nz_median(matrix_test, by = c(1,2,3,1,2,3,1,2,3,1,2))
df_test <- as.data.frame(matrix_test)
nz_median(df_test, by = c(1,2,3,1,2,3,1,2,3,1,2))

brickmanlab/commonR documentation built on Dec. 19, 2021, 11:44 a.m.