Learn R Programming

omnibus (version 1.2.15)

runifMatrix: Matrix of random values, possibly with standardization by row or column

Description

This function creates a matrix populated by random uniform values and (at the user's discretion), standardizes the rows, columns, or entire matrix so values sum to 1.

Usage

runifMatrix(nrow, ncol, min = 0, max = 1, stand = NULL)

Value

A numeric matrix.

Arguments

nrow, ncol

Number of rows and columns.

min, max

Minimum and maximum value of values.

stand

Any of:

  • NULL (default): No standardization.

  • 'rows': Standardize so rows sum to 1.

  • 'columns': Standardize so columns sum to 1.

  • 'matrix': Standardize so all values sum to 1.

Partial matching is used and case is ignored.

Examples

Run this code

rows <- 4
cols <- 3

runifMatrix(rows, cols)

standByRows <- runifMatrix(rows, cols, stand = 'r')
standByRows
rowSums(standByRows)

standByCols <- runifMatrix(rows, cols, stand = 'c')
standByCols
colSums(standByCols)

standByMe <- runifMatrix(rows, cols, stand = 'm')
standByMe
sum(standByMe) # whenever you're in trouble

Run the code above in your browser using DataLab