Learn R Programming

Patterns (version 1.4)

replaceUp: Replace matrix values triangular upper part and by band for the lower part.

Description

F matrices utility function.

Usage

replaceUp(a, b, k)

Value

A matrix (same size as a)

Arguments

a

The matrix to be replaced

b

The matrix with the replacement values

k

The extend of the replacement: 0 (upper part only), 1 (upper part and first extra diagonal), in general an entry is replaced if (row(a) - col(a)) <= k

Author

Bertrand Frederic, Myriam Maumy-Bertrand.

Examples

Run this code

a=matrix(1:9,3,3)
b=matrix(1,3,3)
replaceUp(a,b,0)
replaceUp(a,b,1)
replaceUp(a,b,2)

Run the code above in your browser using DataLab