rmatrix: Generating Random Matrices

Description Usage Arguments Methods (by generic) Examples

Description

The S4 generic rmatrix generates a random matrix from a given object. Methods are provided to generate matrices with entries drawn from any given random distribution function, e.g. runif or rnorm.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
rmatrix(x, ...)

## S4 method for signature 'numeric'
rmatrix(
  x,
  y = NULL,
  dist = runif,
  byrow = FALSE,
  dimnames = NULL,
  ...,
  .rng = NULL
)

## S4 method for signature 'ANY'
rmatrix(x, ...)

rmatrix_int(...)

Arguments

x

object from which to generate a random matrix

...

extra arguments passed to the distribution function dist, or to rmatrix in the case of rmatrix_int.

y

optional specification of number of columns

dist

a random distribution function or a numeric seed (see details of method rmatrix,numeric)

byrow

a logical passed in the internal call to the function matrix

dimnames

NULL or a list passed in the internal call to the function matrix.

If dimnames = TRUE, then row and column names are added as [r1, r2, ...] and [c1, c2, ...].

.rng

any RNG seed specification supported by setRNG.

Methods (by generic)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
## Generate a random matrix of a given size
rmatrix(5, 3)


## Generate a random matrix of the same dimension of a template matrix
a <- matrix(1, 3, 4)
rmatrix(a)


## Specificy the distribution to use

# the default is uniform
a <- rmatrix(1000, 50)
## Not run:  hist(a) 

# use normal ditribution
a <- rmatrix(1000, 50, rnorm)
## Not run:  hist(a) 

# extra arguments can be passed to the random variate generation function 
a <- rmatrix(1000, 50, rnorm, mean=2, sd=0.5)
## Not run:  hist(a) 


# random matrix of the same dimension as another matrix
x <- matrix(3,4)
dim(rmatrix(x))

renozao/NMF documentation built on June 14, 2020, 9:35 p.m.