Matrix                package:Matrix                R Documentation

_C_o_n_s_t_r_u_c_t _a _C_l_a_s_s_e_d _M_a_t_r_i_x

_D_e_s_c_r_i_p_t_i_o_n:

     Construct a Matrix of a class that inherits from 'Matrix'.

_U_s_a_g_e:

     Matrix(data=NA, nrow=1, ncol=1, byrow=FALSE, dimnames=NULL,
            sparse = NULL, forceCheck = FALSE)

_A_r_g_u_m_e_n_t_s:

    data: an optional numeric data vector or matrix.

    nrow: when 'data' is not a matrix, the desired number of rows

    ncol: when 'data' is not a matrix, the desired number of columns

   byrow: logical.  If 'FALSE' (the default) the matrix is filled by
          columns, otherwise the matrix is filled by rows.

dimnames: a 'dimnames' attribute for the matrix: a 'list' of two
          character components.  They are set if not 'NULL' (as per
          default).

  sparse: logical or 'NULL', specifying if the result should be sparse
          or not.  By default, it is made sparse when more than half of
          the entries are 0.

forceCheck: logical indicating if the checks for structure should even
          happen when 'data' is already a '"Matrix"' object.

_D_e_t_a_i_l_s:

     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.
     Further, 'Matrix()' makes efforts to keep 'logical' matrices
     logical, i.e., inheriting from class 'lMatrix', and to determine
     specially structured matrices such as symmetric, triangular or
     diagonal ones.  Note that a _symmetric_ matrix also needs
     symmetric 'dimnames', e.g., by specifying 'dimnames =
     list(NULL,NULL)', see the examples.

     Most of the time, the function works via a traditional (_full_)
     'matrix'.  However, 'Matrix(0, nrow,ncol)' directly constructs an
     "empty" sparseMatrix, as does 'Matrix(FALSE, *)'.

     Although it is sometime possible to mix unclassed matrices
     (created with 'matrix') with ones of class '"Matrix"', it is much
     safer to always use carefully constructed ones of class
     '"Matrix"'.

_V_a_l_u_e:

     Returns matrix of a class that inherits from '"Matrix"'. Only if
     'data' is not a 'matrix' and does not already inherit from class
     'Matrix' are the arguments 'nrow', 'ncol' and 'byrow' made use of.

_S_e_e _A_l_s_o:

     The classes 'Matrix', 'symmetricMatrix', 'triangularMatrix', and
     'diagonalMatrix'; further, 'matrix'.

     Special matrices can be constructed, e.g., via 'sparseMatrix'
     (sparse), 'bdiag' (block-diagonal), 'bandSparse' (banded sparse),
     or 'Diagonal'.

_E_x_a_m_p_l_e_s:

     Matrix(0, 3, 2)             # 3 by 2 matrix of zeros -> sparse
     Matrix(0, 3, 2, sparse=FALSE)# forced 'dense'
     Matrix(1:6, 3, 2)           # a 3 by 2 matrix (+ integer warning)
     Matrix(1:6 + 1, nrow=3)

     ## logical ones:
     Matrix(diag(4) >  0)# -> "ldiMatrix" with diag = "U"
     Matrix(diag(4) >  0, sparse=TRUE)# -> sparse...
     Matrix(diag(4) >= 0)# -> "lsyMatrix" (of all 'TRUE')
     ## triangular
     l3 <- upper.tri(matrix(,3,3))
     (M <- Matrix(l3))  # -> "ltCMatrix"
     Matrix(! l3)# -> "ltrMatrix"
     as(l3, "CsparseMatrix")

     Matrix(1:9, nrow=3,
            dimnames = list(c("a", "b", "c"), c("A", "B", "C")))
     (I3 <- Matrix(diag(3)))# identity, i.e., unit "diagonalMatrix"
     str(I3) # note the empty 'x' slot

     (A <- cbind(a=c(2,1), b=1:2))# symmetric *apart* from dimnames
     Matrix(A)                    # hence 'dgeMatrix'
     (As <- Matrix(A, dimnames = list(NULL,NULL)))# -> symmetric
     stopifnot(is(As, "symmetricMatrix"),
               is(Matrix(0, 3,3), "sparseMatrix"),
               is(Matrix(FALSE, 1,1), "sparseMatrix"))

