J Function

J (nrow <, ncol> <, value> ) ;

The J function creates a matrix with nrow rows and ncol columns with all elements equal to value.

The arguments to the J function are as follows:

nrow

is a numeric matrix or literal that contains the number of rows.

ncol

is a numeric matrix or literal that contains the number of columns.

value

is a numeric or character matrix or literal for filling the rows and columns of the matrix.

If ncol is not specified, it defaults to nrow. If value is not specified, it defaults to 1. The REPEAT and SHAPE functions can also perform this operation, and they are more general.

Examples of the J function are as follows:

b = j(3, 4);
c = j(5, 2, "xyz");
print b, c;

Figure 23.156: Constant Matrices

b
1 1 1 1
1 1 1 1
1 1 1 1

c
xyz xyz
xyz xyz
xyz xyz
xyz xyz
xyz xyz