columnwisePercentage: Columnwise Percentage

View source: R/stat.R

columnwisePercentageR Documentation

Columnwise Percentage

Description

Calculate the percentage (value divided by sum of values in the column) for each column

Usage

columnwisePercentage(x, default = 0, digits = 1)

Arguments

x

two dimensional numeric data structure

default

default value to be used if the calculated percentage is NA.

digits

number of digits (default: 1) to which the resulting percentages are to be rounded. Set to NA to suppress rounding

Examples

# Create a random matrix of integer values
M1 <- matrix(sample(100, 12), nrow = 4, dimnames = list(LETTERS[1:4], 1:3))

# Introduce some NA
values <- as.numeric(M1)
values[sample(length(values), 3)] <- NA
M2 <- matrix(values, nrow = nrow(M1), dimnames = dimnames(M1))

M1
columnwisePercentage(M1)

M2
columnwisePercentage(M2)
columnwisePercentage(M2, default = 0)


KWB-R/kwb.utils documentation built on April 1, 2024, 7:12 a.m.