[ top | up ]

Create a Matrix

Syntax

matrix(data=NA, nrow=1, ncol=1, byrow=false)
as.matrix(x)
is.matrix(x)

Description

matrix creates a matrix from the given set of values. nrow gives the desired number of rows and ncol the desired number of columns. If either of nrow or ncol is not given, an attempt is made to infer it from the length of data and the other parameter. If byrow is false (the default) the matrix is filled by columns, otherwise the matrix is filled by rows.

as.matrix attempts to force its argument to be a matrix by attaching a dim attribute to it.

is.matrix returns true if x is an matrix (i.e. it has a dim attribute of length 2) and false otherwise.