nz_mean: Non-zero mean of data frames, matrices or vectors

Description Usage Arguments Value Examples

View source: R/functions.R

Description

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

Usage

1
nz_mean(x, by = NULL)

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 mean of x or non zero mean of groups of columns in x.

Examples

1
2
3
4
5
6
vector_test <- c(rep(0,10),1:100)
nz_mean(vector_test)
matrix_test <- matrix(c(rep(0,10),1:100),nrow=10)
nz_mean(matrix_test, by = c(1,2,3,1,2,3,1,2,3,1,2))
df_test <- as.data.frame(matrix_test)
nz_mean(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.